Sunday, December 22, 2019

unity - How to move one object to another object's position


So I'm want to move one game object (my player) to the position of another game object, on keyDown. I'm just not sure how to reference the position of the object which is where I want my player to move(or teleport) to.


I know a couple different was to move my player, but I don't know what variable or statement I would use to reference the other objects position.


(Also the thing I'm teleporting to is not moving). I really appreciate any help you can give me.


public class GetInCar : MonoBehaviour {
public GameObject player;
public GameObject car;
//public Camera cam1;


void OnMouseDown () {
if (Input.GetKey (KeyCode.Mouse0)) {
player.transform.rotation = car.transform.rotation;
print("MovedToCar");
GameObject.Find ("Player").GetComponent ().enabled = false;

//cam1.enabled = true;
}
}

}


No comments:

Post a Comment

Simple past, Present perfect Past perfect

Can you tell me which form of the following sentences is the correct one please? Imagine two friends discussing the gym... I was in a good s...