Hi, i've been having trouble with this concept from the beginning. I've seen scripts in which people will use a variable and then reassign it. When are you allowed to do that, and when is it not allowed?
void MoveDoors(float newLeftXtarget, float newRightXtarget) //when called we will lerp only the x position of each inner door that will follow the closing outer doors
{
float newX = Mathf.Lerp (leftInnerDoor.position.x, newLeftXtarget, doorSpeed * Time.deltaTime); //using mathF.lerp instead of vector3.lerp because only the X position is being lerped...
leftInnerDoor.position = new Vector3(newX,leftInnerDoor.position.y, leftInnerDoor.position.y); // setting positon of door with new offset x position coordinate
newX = Mathf.Lerp (rightInnerDoor.position.x, newRightXtarget, doorSpeed * Time.deltaTime);
rightInnerDoor.position = new Vector3(newX,rightInnerDoor.position.y, rightInnerDoor.position.z); // ????? reassigning var
}
In this code for instance the variable newX is reassigned to be used again for a Mathf.Lerp. Can someone help me in the understanding of reassigning a variable. Its somewhat fustrating because i've never been able to understand the idea behind it.
↧