Created
April 16, 2021 07:31
-
-
Save GT3000/0a25b5d9942936b19a2fee59b5f94a50 to your computer and use it in GitHub Desktop.
Simple Color Change Trigger script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections; | |
using System.Collections.Generic; | |
using UnityEngine; | |
public class ChangeColor : MonoBehaviour | |
{ | |
// Start is called before the first frame update | |
void Start() | |
{ | |
} | |
// Update is called once per frame | |
void Update() | |
{ | |
} | |
private void OnTriggerEnter(Collider other) | |
{ | |
//when player object enters the trigger collider, turn it blue | |
if (other.gameObject.GetComponent<Player>()) | |
{ | |
other.gameObject.GetComponent<MeshRenderer>().material.SetColor("_Color", Color.blue); | |
} | |
} | |
private void OnTriggerExit(Collider other) | |
{ | |
//when player object leaves the trigger collider, turn it grey | |
if (other.gameObject.GetComponent<Player>()) | |
{ | |
other.gameObject.GetComponent<MeshRenderer>().material.SetColor("_Color", Color.grey); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment