Search Unity

Enable Disable Mesh Renderer

Discussion in 'Editor & General Support' started by CoolCosmos, Dec 14, 2016.

  1. CoolCosmos

    CoolCosmos

    Joined:
    Nov 21, 2016
    Posts:
    247
    Hello,

    I created an object whose mesh renderer is disabled, I want it to be Enabled when mouse goes on it and disable when mouse goes out, can you help me pls :( ?


    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;

    public class DeactivateScript : MonoBehaviour
    {
    public GameObject PLS ;(

    void OnMouseEnter()
    {

    }

    void OnMouseExit()
    {

    }

    void OnMouseOver()
    {

    }
    }
     
  2. CoolCosmos

    CoolCosmos

    Joined:
    Nov 21, 2016
    Posts:
    247
    pls reply, its important for me :/
     
  3. Alekxss

    Alekxss

    Joined:
    Mar 25, 2013
    Posts:
    170
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class DeactivateScript : MonoBehaviour
    6. {
    7. public MeshRenderer PLS;
    8.  
    9. void OnMouseEnter()
    10. {
    11. PLS.enabled=true;
    12. }
    13.  
    14. void OnMouseExit()
    15. {
    16. PLS.enabled=false;
    17. }
    18.  
    19. void OnMouseOver()
    20. {
    21.  
    22. }
    23. }
     
  4. CoolCosmos

    CoolCosmos

    Joined:
    Nov 21, 2016
    Posts:
    247
    Thanks bro Aily, it works excellent, thank you so much :]
     
  5. CsabCsab

    CsabCsab

    Joined:
    Feb 8, 2020
    Posts:
    2
    Thank you for your help Much appreciated :)
     
    Deleted User and HarryGeoffrion like this.
  6. Deleted User

    Deleted User

    Guest

    that is so useful tysm
     
  7. alvaja

    alvaja

    Joined:
    May 27, 2022
    Posts:
    1
    Thx for the basic information of the MeshRenderer because now I can just change the MeshRenderer into BoxCollider and have a moving/disapearing door that I can put in my level
     
  8. teatime_penguin

    teatime_penguin

    Joined:
    May 3, 2022
    Posts:
    25
    this was really helpful thx
     
  9. simonazaal

    simonazaal

    Joined:
    Oct 25, 2021
    Posts:
    1
    yeah
     

    Attached Files: