Не удалось изменить возвращаемое значение "Transform.position", т.к. оно не является переменной - C#
Формулировка задачи:
Не удалось изменить возвращаемое значение "Transform.position", т.к. оно не является переменной.
Ошибка на 13 строке. Просьба помочь!
Листинг программы
- private CharacterController charController;
- private Transform theTransform;
- private float charHeight;
- private void Update()
- {
- var h = charHeight;
- if (Input.GetKey("С"))
- {
- h = charHeight * 0.5f;
- }
- var lastHeight = charController.height;
- charController.height = Mathf.Lerp(charController.height, h, 5 * Time.deltaTime);
- theTransform.position.y += (charController.height - lastHeight) / 2;
- }
- }
Вот весь код...
Листинг программы
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class CrouchHeight : MonoBehaviour {
- private CharacterController charController;
- private Transform theTransform;
- private float charHeight;
- private void Start()
- {
- theTransform = transform;
- charController = GetComponent<CharacterController>();
- charHeight = charController.height;
- }
- private void Update()
- {
- var h = charHeight;
- if (Input.GetKey("С"))
- {
- h = charHeight * 0.5f;
- }
- var lastHeight = charController.height;
- charController.height = Mathf.Lerp(charController.height, h, 5 * Time.deltaTime);
- theTransform.position.y += (charController.height - lastHeight) / 2;
- }
- }
Решение задачи: «Не удалось изменить возвращаемое значение "Transform.position", т.к. оно не является переменной»
textual
Листинг программы
- var position = theTransform.position;
- position.y += (charController.height - lastHeight) / 2;
- theTransform.position = position;
ИИ поможет Вам:
- решить любую задачу по программированию
- объяснить код
- расставить комментарии в коде
- и т.д