Hi I want to attach an object I instantiated to fit the transform of my character when a powerup is collided with. But when I set the object’s transform the results are not as what I was expecting. How could I fix the equipment’s transform to a position and rotation I want to have.
Here is my script for my powerup:
public GameObject chainsawAttachment;
GameObject playerObject;
// Use this for initialization
void Start () {
playerObject = GameObject.Find("PlayerCar");
animation["chainsawRotate"].wrapMode = WrapMode.Loop;
}
void OnTriggerEnter (Collider myTrigger){
if (myTrigger.gameObject.tag == "Player") {
GameObject equipedChainsaw = (GameObject)Instantiate(chainsawAttachment,new Vector3( playerObject.transform.localPosition.x, playerObject.transform.localPosition.y, playerObject.transform.localPosition.z), Quaternion.Euler(playerObject.transform.rotation.x, playerObject.transform.rotation.y, playerObject.transform.rotation.z));
equipedChainsaw.transform.parent = playerObject.transform;
Destroy(gameObject);
}
}