Last active
August 8, 2020 06:17
-
-
Save seferciogluecce/2710fa18cfb9f06de3ced75588fed165 to your computer and use it in GitHub Desktop.
Tutorial: https://youtu.be/wBEAiH3_CFk
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 UnityEngine; | |
[RequireComponent(typeof(MeshRenderer))] | |
[RequireComponent(typeof(Collider))] | |
[RequireComponent(typeof(DragAndShoot))] | |
public class MaterialChanger : MonoBehaviour | |
{ | |
public Material CorrectMat; | |
public Material WrongMat; | |
private MeshRenderer m_meshRenderer; | |
private DragAndShoot m_dragAndShoot; | |
public string TargetGameObjectTag = "Wall"; | |
public string UnWantedGameObjectTag = "Ground"; | |
private void Start() | |
{ | |
m_meshRenderer = GetComponent<MeshRenderer>(); | |
m_dragAndShoot = GetComponent<DragAndShoot>(); | |
} | |
private void OnCollisionEnter(Collision other) | |
{ | |
if (!m_dragAndShoot.IsShoot()) | |
{ | |
return; | |
} | |
if (other.gameObject.CompareTag(TargetGameObjectTag)) | |
{ | |
m_meshRenderer.material = CorrectMat; | |
} | |
else if (other.gameObject.CompareTag(UnWantedGameObjectTag)) | |
{ | |
m_meshRenderer.material = WrongMat; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment