Reputation: 341
I have a problem. I want that if player click on StudyOutDoor, first the object move toward to the door, then change the scene in Unity. here is my code:
if (Physics.Raycast (clickPoint, out hitPoint)) {
if (hitPoint.collider.name == "StudyOutDoor") {
target.y = transform.position.y;
target.z = transform.position.z;
transform.position = Vector3.MoveTowards (transform.position, target, playerSpeed * Time.deltaTime);
sceneNumber = 3;
Application.LoadLevel("Corridor");
}
But it is just changing the scene without moving toward to the position I said. Please help.
Upvotes: 3
Views: 303
Reputation: 2683
the object does move toward the door, you just don't see it because you load the new level in the same frame. what happens in detail:
what you want to do:
to achieve this, you should set a bool flag that moves the object only when the ray was hit
pseudo code:
update()
{
if( ray cast hit )
{
calculate target position
set flag to true
}
if( flag )
{
move object to target position
if( object reached target position )
{
load new level
}
}
}
Upvotes: 1