Day #002

#DAY002

Turning the renderer on/off with mouse-press of another game object.

The renderer is the property of an object that makes it “visible”.

Main points covered

#publicGameObjects

#GetMouseButton

#<MeshRenderer>

C# script (attached to anything)

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

public class RendererOnOff : MonoBehaviour {

public GameObject otherGameObject;

void Update () {
if (Input.GetMouseButton(0)) {
otherGameObject.gameObject.GetComponent<MeshRenderer> ().enabled = false;
} else {
otherGameObject.gameObject.GetComponent<MeshRenderer> ().enabled = true;
}
}
}

———————–

Obs:

GetMouseButton works as long as you keep the button pressed

Int “0” is left click

Int “1” is right click

Int “2” is middle button

Leave a Reply

Your email address will not be published. Required fields are marked *