Hello. I need to make it so multiple game objects do not fall forward or backwards, as to kind of act like a 2d game. An alternative to the tag would be to have the script on each gameObject. This method would actually be preferred. Thank you! -Keavon
Try (Didn't test):
var yAxis;
function Awake ()
{
yAxis = transform.position.y;
}
function Update ()
{
transform.position.y = yAxis;
}
That MIGHT work.
You could manually go through and add components to all the objects that you want. If you wanted a script to do it at runtime, you could do something like this which will add them automatically for you:
//SceneManager.js
//This goes somewhere in your scene.
function Awake () {
var specialObjs : GameObject[] = GameObject.FindGameObjectsWithTag("SomeTag");
for(var obj : GameObject in specialObjs) {
var comp : KeepOnZ = obj.AddComponent(KeepOnZ);
comp.Init();
//You could probably let Start() call itself in your other script.
}
}
//KeepOnZ.js
var zDepth : float;
function Init () {
zDepth = transform.position.z;
//Initialize your script.
}
function Update () {
transform.position.z = zDepth;
//if you are going to be locked on the z-axis, then you can do:
//transform.position.z = 0.0;
//Or you could add some joints to lock its position as well.
//Probably a Configurable joint.
transform.eulerAngles.z = 0;
//Don't let it rock side to side.
}