Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- //I removed the OnCollisionEnter method here, as the Scorer script now handles the material color change by calling the HitObject() method
- public class ObjectHit : MonoBehaviour
- {
- //boolean field if the object has been hit, default is false
- private bool isHit;
- //public get-only property to allow other scripts to access this variable
- //(you could have also made the above bool isHit public, but this way other scripts can only read the value of the boolean field and not change it)
- public bool IsHit => isHit;
- public void HitObject()
- {
- //if we have been hit already, we do nothing
- if(isHit)
- return;
- //we set the bool isHit field to true
- isHit = true;
- GetComponent<MeshRenderer>().material.color = Color.black;
- }
- }
Add Comment
Please, Sign In to add comment