Reputation: 37
using UnityEngine; using System.Collections;
public class playSound : MonoBehaviour {
private bool destructionHasBegun = false;
public Transform BlueKey;
private void OnTriggerEnter()
{
audio.Play ();
destructionHasBegun = true;
}
private void Update()
{
if(destructionHasBegun)
{
DestroyWhenSoundComplete();
}
}
private void DestroyWhenSoundComplete()
{
if(!audio.isPlaying)
{
Destroy(gameObject);
GameObject textObject = (GameObject)Instantiate(Resources.Load("BlueKey"));
}
}
}
im trying to instantiate the bluekey prefab in a particular position how do i do this? thanks in advance
Upvotes: 2
Views: 3772
Reputation: 6169
As per the Instantiate
documentation, you can pass in a Vector3 worldspace position as a second parameter.
You'll also need to pass in a Quaternion for its initial rotation as the third parameter; Quaternion.identity
is the equivalent of no rotation.
Vector3 newPosition = new Vector3(0, 0, 0);
Quaternion newRotation = Quaternion.identity;
GameObject textObject = (GameObject)Instantiate(Resources.Load("BlueKey"), newPosition, newRotation);
Upvotes: 0