private var myTransform : Transform;
function Start()
{
myTransform = transform;
// Main loop
while (true)
{
myTransform.position.z = Mathf.Lerp (myTransform.position.z, gridSize, fastLane);
yield;
}
}
But when I try to put the myTransform.position.z line in C#, I’m getting an error that says consider storing the value in a temporary variable. I found online how to store the values but I’m getting error can’t convert Vector3 to float. Is there something I’m missing? Hope someone can help.
As far as I can tell, C# does not allow you to access individual values (x,y,z) of transforms. You have to assign it an entirely new vector3.
using UnityEngine;
using System.Collections;
//test class, you might want to change this name
public class test : MonoBehaviour
{
private Transform myTransform;
//I threw these 2 variables in to get rid of errors
private float gridSize = 0f;
private float fastLane = 0f;
void Start()
{
myTransform = transform;
// Main loop
while (true)
{
//this is basically saying, assign a new vector to position, and keep the current x and y values,
// but do something different for z.
myTransform.position = new Vector3(myTransform.position.x, myTransform.position.y,
Mathf.Lerp (myTransform.position.z, gridSize, fastLane));
yield;// <--No idea what this is O_o
}
}