Question by
tomatuxtemple · Oct 06, 2020 at 10:20 AM ·
rigidbodytriggerspawn
Spawn object doesn't trigger an object to move,Problem with trigger and spawned objects
I have a spawner with this code
public class shootFromSpots : MonoBehaviour
{
public Rigidbody projectile;
public float spawnWait;
public bool stop;
public float moreForce;
public float force = 1500f;
public float speed;
public Transform[] moveSpots;
private int randomSpot;
public float waitTime;
public float startWaitTime;
private Vector3 vector;
void Start(){
StartCoroutine(waitSpawner());
waitTime = startWaitTime;
randomSpot = Random.Range(0, moveSpots.Length);
}
private void Update(){
moreForce = force+= 20f * Time.deltaTime;
transform.position = Vector3.MoveTowards(transform.position, moveSpots[randomSpot].position, speed);
if(Vector3.Distance(transform.position, moveSpots[randomSpot].position) < 0.1f){
if(waitTime <= 0){
randomSpot = Random.Range(0, moveSpots.Length);
waitTime = startWaitTime;
} else {
waitTime -= Time.deltaTime;
}
}
}
IEnumerator waitSpawner(){
while (!stop){
Rigidbody projectileInstance;
projectileInstance = Instantiate (projectile, moveSpots[randomSpot].position, moveSpots[randomSpot].rotation);
vector = randomSpot == 0 ? moveSpots[0].forward : moveSpots[1].right;
projectileInstance.AddForce(vector * moreForce);
yield return new WaitForSeconds (spawnWait);
}
}
}
and i have a trigger with this script
public class showHints : MonoBehaviour
{
public Transform hintH;
public Vector3 hiddenPosition = new Vector3(-0.29f,-0.5f,0);
public Vector3 shownPosition = new Vector3(-0.29f,0.1f,0);
public float showSpeed = 5;
private bool showH = false;
void Update () {
if(showH){
hintH.position = Vector3.Lerp(hintH.position, shownPosition, Time.deltaTime * showSpeed);
} else {
hintH.position = Vector3.Lerp(hintH.position, hiddenPosition, Time.deltaTime * showSpeed);
}
}
private void onTriggerEnter(Collider collider)
{
if (collider.tag == "Ball") {
ShowH();
}
}
private void onTriggerExit(Collider collider)
{
if (collider.tag == "Ball") {
HideH();
}
}
public void ShowH(){
showH = true;
}
public void HideH(){
showH = false;
}
}
my goal is to make a text object move when the instantiated object enters and exists the trigger. it looks to me like the object is not triggering the condition, but im new to unity and not sure what to do?
i found this thread, but dont know how to make sense of it https://answers.unity.com/questions/1107018/collision-with-instantiated-non-moving-objects.html
please help. thank you in advance
Comment
SOLVED - the problem was the lowercase o
in the onTriggerEnter. it should be OnTriggerEnter
Your answer
Follow this Question
Related Questions
OnTriggerEnter no longer works 1 Answer
Help with Water Buoyancy Physics (using a trigger) 0 Answers
OnTriggerEnter Not working? 1 Answer