Hi folks,
I’m new to programming, and I’m bit lost with something :
I’ve got a var speed, which is set to x.
I save the x value inside another var save.
I then want to give another value to my var speed, for instance y.
Then, I want to use the former value, by setting my var speed equal to the var save.
The concern is that var speed is still equal to y.
What am I doing wrong?
I think that it’s because I’m working in the Update() method, and it’s frame related, but I don’t know how to work around.
Any advice?
void Update()
{
GameObject model = GameObject.Find("Model");
float speedX = speed;
//Get inputs
float moveH = Input.GetAxis("Horizontal");
float moveV = Input.GetAxis("Vertical");
//Player Character grounded
if (Physics.Raycast(transform.position, Vector3.down, 1f))
{
//Move
transform.Translate(new Vector3(moveH, 0, moveV) * Time.deltaTime * speed);
}
//Player Character !grounded
else
{
//Move + Fall
transform.Translate(new Vector3(moveH, -1, moveV) * Time.deltaTime * speed);
if (model.transform.rotation.x < 0.50)
{
model.transform.Rotate(new Vector3(120, 0, 0) * Time.deltaTime, Space.World);
}
else if (model.transform.rotation.x > 0.50)
{
model.transform.Rotate(new Vector3(0, 0, 0));
if (Input.GetKey(KeyCode.Space))
{
if (model.transform.rotation.x < 0.90)
{
model.transform.Rotate(new Vector3(120, 0, 0) * Time.deltaTime, Space.World);
speed = 15;
}
}
else
{
if (model.transform.rotation.x > 0.50)
{
model.transform.Rotate(new Vector3(-120, 0, 0) * Time.deltaTime, Space.World);
speed = speedX;
}
}
}
}
}