- Home /
Start Method and scene hierarchy
I'm new in unity ev and tried many ways (used to try some options by myself) and I can't figure out how to set this procedure
Start -> LoadLevel (Scene) // It works
Now if loaded Scene(name) init methods // I've done it so
Update player position of method
// This part of init wont work like i want it is called from Update and it start as Main_Menu Scene is loaded
This is part of code is connected =
//Location
Vector2 pos;
public float slow = 5f;
public float destP;
private float startP;
//StartFlag
bool start;
// Use this for initialization
void Start () {
pos = transform.position;
startP = pos.x;
start = true;
}
// Update is called once per frame
void Update () {
if(start) {
ToPosAtStart ();
}
}
public void ToPosAtStart() {
if (pos.x != destP) {
pos.x = Mathf.Lerp (startP,destP,Time.time / slow);
transform.position = new Vector2 (pos.x,pos.y);
Debug.Log ("Start is True like life suck is true kappa");
}
}
Answer by b1gry4n · Oct 15, 2016 at 01:19 PM
Do you want the transform to slide across to the desired spot or do you want it to start at the desired spot? Youre making it more complex than it has to be.
if you want it to teleport instantly:
public Vector3 desiredStart;
void Start()
{
transform.position = desiredStart;
}
if you want it to slide:
bool isSetup = false;
void Update()
{
if (!isSetup)
{
float distance = Vector3.Distance(transform.position, desiredStart);
if (distance > 0.1f)
{
transform.position = Vector3.Lerp(transform.position, desiredStart, Time.deltaTime / slow);
}
else {
isSetup = true;
}
}
}
I see you know what i want to do but problem is that it is called as I hit play button (this one from load level) but the script has been called before.
And it looks like this depend of time you run game you can see it setting up at position or it is just on it because of flown time.