- Home /
Paint trees with scripts?
I want to paint trees on my terrain, though when i go ingame, the script does no longer work on it, and i don't want to manualy place every tree.
I have no idea how i should fix it, and i need some help.
Script on the trees: using System.Collections; using System.Collections.Generic; using UnityEngine.Timeline; using UnityEngine;
public class add : MonoBehaviour {
public int health;
public int res;
private bool dead = false;
private float time = 0f;
void Start () {
}
private void OnMouseDown()
{
if (health >= 2)
{
health--;
} else
{
resources.wood = resources.wood + res;
gameObject.SetActive(false);
time = Random.Range(100, 200);
dead = true;
}
}
void Update () {
if (dead == true)
{
if (time > 1)
{
time -= Time.deltaTime;
} else
{
gameObject.SetActive(true);
dead = false;
health = 10;
}
}
}
}
Thank you
Jessa
Answer by MT369MT · May 29, 2018 at 09:09 PM
Hi, I see you used gameObject.SetActive(false); if you disable the gameObject also the script will no longer work and your conditions in Update are useless because they will never be called. But I didn’t understand well how this script work and what you want to do. And is this script attached to your trees or your player?
It works. It does. It's on trees. On a prefab placed tree it does. Though on a painted trees it doesn't even get called / activated in any way.