I have the following:
void OnTriggerExit()
{
renderer.material.color = _startColor;
this.transform.position.z = -7.6;
}
I would like to move the z position of the object that just got triggered to -7.6 but this gives me an error. Can someone tell me how I can move it?
It looks like you have several issues here. If you look at the error that Unity gives you, it’s actually pretty helpful, but I’ll just solve it for you here:
-First, the format for single float numbers in C# requires an f at the end, otherwise they are treated as doubles, and you’ll get an error. So you need to change -7.6 to -7.6f.
-Second, you can’t just assign directly to the x, y, and z of a transform.position. You have to assign a new Vector3, like so:
Vector3 newPosition = new Vector3(0f, 0f, -7.6f);
this.transform.position = newPosition;