Question by
Unity_GEAR · Jun 03 at 10:17 PM ·
collisiongameobjectrenderingshadersrenderer
Trouble with having object appear when an something is hovering over it and disapear if something Isn't
Hey, I'm sort of new to programming and having a hard time trying to make it so the render of the object disappears when something Isn't hovering over it, but if something is the object is rendered. Here is my code if anyone could help!
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Enemy_Visable : MonoBehaviour
{
[SerializeField]
public GameObject Enemy;
void Start()
{
Enemy.GetComponent<Renderer>().enabled = false;
}
void OnTriggerEnter(Collider other)
{
if (other.CompareTag("Sphere"))
{
Enemy.GetComponent<Renderer>().enabled = true;
}
}
void OnTriggerExit(Collider other)
{
if (other.CompareTag("Sphere"))
{
Enemy.GetComponent<Renderer>().enabled = false;
}
}
}
Comment
Your answer
Follow this Question
Related Questions
Collider and Renderer desync 0 Answers
Error CS1519 1 Answer
How to get parent with component on collision? 0 Answers
Broken colors when updating from Unity 2017 to 2018 0 Answers
Is there a limit to the number of CustomRenderTexture dependencies? 0 Answers