Hello. I am writing a fairly simple game like fps shooter. Faced a problem, namely:

Vector3 mov_horizontal = transform.right = xMov; Vector3 mov_vertical = transform.forward = zMov; 

The compiler swears at xMov && zMov, writes:

Cannot implicitly convert type "float" to "UnityEngine.vector3"

Who to share a possible solution to this problem.

All code:

 using UnityEngine; [RequireComponent(typeof(PlaerModer))] public class PlaerControiler : MonoBehaviour { [SerializeField] private float speed = 5f; private PlaerModer motor; private void Start() { motor = GetComponent<PlaerModer>(); } private void Update() { float xMov = Input.GetAxisRaw("Horizontal"); float zMov = Input.GetAxisRaw("Vertical"); //Ошибка здесь Vector3 mov_horizontal = transform.right = xMov; Vector3 mov_vertical = transform.forward = zMov; Vector3 velocity = (mov_horizontal + mov_vertical).normalized * speed; motor.Move(velocity); } } 

Now the error looks like this: enter image description here

    1 answer 1

      Vector3 right = new Vector3(xMov, transform.right.y, transform.right.z); transform.right = right; Vector3 forward = new Vector3(transform.forward.x, transform.forward.y, zMov); transform.forward = forward; Vector3 velocity = (new Vector3(xMov, 0, zMov)).normalized * speed; 
    • All the same, swears at the line transform.right = xMov; - Isaac Asimov
    • one
      @ IsaacAzimov in response to the line does not look like this - tym32167
    • @ tym32167 This is what I just fixed. - Igor
    • and then there are no questions - tym32167
    • @Igor Could not change the return value of "tramsgform.right" because it is not variable - Isaac Asimov