I have 12 objects using the same script below, I need them to each activate individually of each other.
using System.Collections; using System.Collections.Generic; using System.Collections.Specialized; using System.Runtime.InteropServices; using System.Security; using System.Security.Cryptography.X509Certificates; using UnityEngine; public class Plant : MonoBehaviour { public bool seed; public float Water; // Start is called before the first frame update void Start() { Debug.Log("I am alive"); } // Update is called once per frame void Update() { { if (Input.GetMouseButtonDown(0)) { Vector3 mousePos = Camera.main.ScreenToWorldPoint(Input.mousePosition); Vector2 mousePos2D = new Vector2(mousePos.x, mousePos.y); RaycastHit2D hit = Physics2D.Raycast(mousePos2D, Vector2.zero); if (hit.collider == gameObject.name) { this.seed = true; } } } if (Water <= 0) { this.seed = false; this.Water = 100; Debug.Log("I have died :("); } if (this.seed == true) { this.Water = this.Water - 1 * Time.deltaTime; } Debug.Log("Water is now " + this.Water); } }
I can't seem to get it to work. They all run, or they don't run. I have yet to reference the game object's collider correctly. So only the one clicked will start.
Your answer
Follow this Question
Related Questions
videoPlayer Script Help Needed 0 Answers
Why does Unity lock the transform of prefabs in my scene in playmode? 0 Answers
ScriptName versus PingPongScriptName? 0 Answers
Input Command Issues 0 Answers