Hello!
I am following a tutorial for C# in which we make a variable called Vector3 Move. Then in Update we write Vector3 Move = new Vector3(Input.GetAxis(“Horizontal”), 0, Input.GetAxis(“Vertical”));
The tutorial does not seem to explain why we define these two separate variables with the same name, but they don’t seem to correspond. I have even noted out the top Vector3 Move and the script works the exact same. I am sure there is a reason to write it like this but I don’t know what it is.
Here is the tutorial video:
Here is my script:
using UnityEngine;
using System.Collections;
[RequireComponent(typeof(Rigidbody))]
public class PlayerMove : MonoBehaviour {
public Rigidbody rb;
public int PlayerSpeed = 10;
public float maxSpeed = 5.0f;
public bool grounded = false;
public GameObject floor;
Vector3 Move; //?? Why do this if Vector3 Move is done in update also?
void Start()
{
rb = GetComponent<Rigidbody>();
}
void Awake()
{
}
void Update()
{
Vector3 Move = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
//This works just fine without the first Vector3??
if (rb.velocity.magnitude < maxSpeed)
{
rb.AddForce(Move * PlayerSpeed);
}
}