If I had any hair Id be pulling it by now, but this one has me stumped
How do I instantiate an object at another object.
To be clearer I have a trigger at position A and once activated I want an object to be created/instantiated at position B ?
I can get triggers to work for other stuff like sound effects or to destroying objects.
The closest Ive got so far just kept instantiating the object at the players location and not at position B.
Well you need to reference position B in some way.
A basic scenario i can think about is if you create an empty game object and place it at your desired “B position” as a reference object / spawner position.
Then, OnTriggerEnter script (or OnTriggerStay or Exit, whichever you use) instantiate the new game object using B’s position and rotation as parameters.
Really basic example:
using UnityEngine;
using System.Collections;
public class SpawnObjectAtB : MonoBehaviour {
public GameObject newObject; //reference in the Inspector the object you want to spawn
public Transform Bobject; //reference in the Inspector the Empty game object you use to choose position and rotation.
void OnTriggerEnter()
{
Instantiate (newObject, Bobject.position, Bobject.rotation);
}
}
You can also manually write a Vector3 and Quaternion instead of referencing the “B position empty game object”, but I believe it would not be design wise/friendly at all.
Hope this answers your question, I’m not native english speaker so I might write in a bit confusing way:p.