i want made a switch between a first and third person gameobjects, and keep the last unique position…can i do this?
i have this:
var first : GameObject;
var third : GameObject;
var playerpos1 : Vector3 = first.transform.position;
var playerpos3 : Vector3 = third.transform.position;
function Update ()
{
if(Input.GetKeyDown(KeyCode.C))
{
if (first.activeSelf == true)
{
third.SetActive(true);
third.transform.position = playerpos1;
first.SetActive(false);
}
else
{
third.SetActive(false);
first.transform.position = playerpos3;
first.SetActive(true);
}
}
}
Duugu
2
You need to cache the transform component (a reference) and not the position (a Vector3 value)
var playerpos1 : Transform = first.transform;
//stuff
third.transform.position = playerpos1.position;
I pull a few hours testing and I could not. I am very noob and not find a way.
var first : GameObject;
var third : GameObject;
var playerpos1 : Transform = first.transform;
var playerpos3 : Transform = third.transform;
function Update () {
if(Input.GetButtonDown("camview")){
if (first.activeSelf == true){
third.SetActive(true);
third.transform.position = playerpos1.position;
first.SetActive(false);
}
else{
first.SetActive(true);
first.transform.position = playerpos3.position;
third.SetActive(false);
}
}
}
and this is the fail result, before and after switch