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