Guest User

Untitled

a guest
Jan 19th, 2025
14
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.77 KB | None | 0 0
  1. using UnityEngine;
  2.  
  3. //I removed the OnCollisionEnter method here, as the Scorer script now handles the material color change by calling the HitObject() method
  4. public class ObjectHit : MonoBehaviour
  5. {
  6. //boolean field if the object has been hit, default is false
  7. private bool isHit;
  8. //public get-only property to allow other scripts to access this variable
  9. //(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)
  10. public bool IsHit => isHit;
  11.  
  12. public void HitObject()
  13. {
  14. //if we have been hit already, we do nothing
  15. if(isHit)
  16. return;
  17.  
  18. //we set the bool isHit field to true
  19. isHit = true;
  20.  
  21. GetComponent<MeshRenderer>().material.color = Color.black;
  22. }
  23. }
Add Comment
Please, Sign In to add comment