Last active
April 23, 2017 07:44
-
-
Save radiatoryang/e5b5fdaaef764c9c5550 to your computer and use it in GitHub Desktop.
simple script, use it with LookCast.cs
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; | |
using System.Collections; | |
// put this script on an object with a COLLIDER | |
public class LookColorChange : MonoBehaviour { | |
// ALL CODE IN "ONLOOK" WILL HAPPEN EVERY FRAME THIS THING IS LOOKED AT | |
void OnLook () { | |
// if we look in console, we should see this message | |
Debug.Log ("this thing is getting looked at!!!"); | |
// ================================================= | |
// SAMPLE EFFECTS YOU COULD DO... | |
// ================================================= | |
// grow in size | |
transform.localScale += Vector3.one * Time.deltaTime; | |
// grow in size 2 times faster | |
transform.localScale += Vector3.one * Time.deltaTime * 2.0f; | |
// change color of object to 100% red | |
// (if no renderer, it will crash) | |
renderer.material.color = new Color(1.0f, 0f, 0f); | |
// turn on a Light (if there is no light, code will crash) | |
light.enabled = true; | |
// make a light increase in intensity as we look at it | |
light.intensity += Time.deltaTime; | |
// if not already playing a sound, then play any sound (AudioSource) on this object; if no AudioSource, will crash | |
if (!audio.isPlaying) { audio.Play (); } | |
// increase volume on any already-playing sound, as we look at it | |
audio.volume += Time.deltaTime; | |
// make physics object fly up if we look at it; will crash if there is no Rigidbody attached | |
rigidbody.AddForce( Vector3.up * Time.deltaTime * 100.0f ); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment