1 rigidbody 2 different trigger, tags doesnt have any meaning?
Hi, im new at coding, trying to learn things.
1- Im trying to make a Tree which spawns seeds,
2- Seeds move away from MotherTree if collides with Wind
3- İf seeds doesnt move or not in spawn location, it turns to Tree.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class NewSeed : MonoBehaviour {
public bool InWindZone = false;
public bool InSpawnLocation = false;
public GameObject windzone;
public GameObject TreeBottom;
public GameObject AırTreePrefab;
public float timetogrow = 15f;
Rigidbody rb;
private void Start ()
{
rb = GetComponent<Rigidbody> ();
}
private void FixedUpdate()
{
if ((!InSpawnLocation) && (rb.velocity == Vector3.zero))
{
timetogrow -= Time.deltaTime;
if (timetogrow <= 0)
{
Instantiate (AırTreePrefab, new Vector3(me.transform.position.x, 0.74f,me.transform.position.z ), Quaternion.identity);
Destroy (me);
}
}
return;
}
void OnTriggerEnter(Collider other)
{
if (other.CompareTag ("WindArea") )
{
InWindZone = true;
InSpawnLocation = false;
rb.AddForce(windzone.GetComponent<WindArea> ().direction * windzone.GetComponent<WindArea> ().strength);
}
if (GameObject.FindWithTag ("SpawnLocation")) {
InSpawnLocation = true;
InWindZone = false;
}
}
void OnTriggerExit(Collider other)
{
if (GameObject.FindWithTag ("SpawnLocation")) {
this.InSpawnLocation = false;
rb.velocity = Vector3.zero;
rb.angularVelocity = Vector3.zero;
}
}
}
Basicly, if i seperate this triggers, i mean if i delete one, other one works, if i put script like this, tags have no meaning, always triggering InSpawnLocation.
Note: I've one script windzone which determines this seed direction and force while in windzone, and tree script but no impact on seed script. Note2: Im messing with this script and changing parts of it, there could be some part of code which is no meaning
Answer by oxydo · Jul 29, 2017 at 09:06 AM
So i fixed it and dont even know what was the issue at first place
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class NewSeed : MonoBehaviour {
public bool InWindZone = false;
public bool InSpawnLocation = false;
public GameObject windzone;
public GameObject TreeBottom;
public GameObject me;
public GameObject AırTreePrefab;
public float timetogrow = 15f;
Rigidbody rb;
private void Start ()
{
rb = GetComponent<Rigidbody> ();
}
private void FixedUpdate()
{
if ((!InSpawnLocation) && (rb.velocity == Vector3.zero))
{
timetogrow -= Time.deltaTime;
if (timetogrow <= 0)
{
Instantiate (AırTreePrefab, new Vector3(me.transform.position.x, 0.74f,me.transform.position.z ), Quaternion.identity);
Destroy (me);
}
}
return;
}
void OnTriggerEnter(Collider other)
{
if (other.gameObject.tag == "SpawnLocation") {
InSpawnLocation = true;
}
}
void OnTriggerStay (Collider other)
{
if (other.CompareTag ("WindArea") )
{
InWindZone = true;
rb.AddForce(windzone.GetComponent<WindArea> ().direction * windzone.GetComponent<WindArea> ().strength );
}
}
void OnTriggerExit(Collider other)
{
if (other.gameObject.tag == "WindArea") {
InWindZone = false;
rb.velocity = Vector3.zero;
rb.angularVelocity = Vector3.zero;
}
if (other.gameObject.tag == "SpawnLocation") {
InSpawnLocation = false;
}
}
}
Your answer
Follow this Question
Related Questions
OnTriggerEnter For Parking 1 Answer
Triggers Colliding With Triggers Not Working? [Solved] 1 Answer
How do I get OnTriggerEnter to work? 1 Answer
Safe Zone when in trigger zone? 0 Answers