Created
August 12, 2015 03:46
-
-
Save khakionion/7919465e85b09b70f198 to your computer and use it in GitHub Desktop.
enable/disable from script
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
//////////////////////////////////////////// | |
//This first class has the Open/Close functionality, put it on a Cube or something | |
//////////////////////////////////////////// | |
using UnityEngine; | |
using System.Collections; | |
public class openclose : MonoBehaviour { | |
// Use this for initialization | |
void Start () { | |
} | |
// Update is called once per frame | |
void Update () { | |
this.transform.Rotate (new Vector3 (0, 1, 0), Time.smoothDeltaTime*5.0f); | |
} | |
public void Open() { | |
this.enabled = true; | |
} | |
public void Close() { | |
this.enabled = false; | |
} | |
} | |
//////////////////////////////////////////// | |
//This next class operates the object above, put it on a Camera or something | |
//////////////////////////////////////////// | |
using UnityEngine; | |
using System.Collections; | |
public class timeroperate : MonoBehaviour { | |
private float TimeLeft = 3.0f; | |
public openclose target = null; | |
// Use this for initialization | |
void Start () { | |
} | |
// Update is called once per frame | |
void Update () { | |
if(target) { | |
TimeLeft -= Time.smoothDeltaTime; | |
if(TimeLeft < 0.0f) { | |
Debug.Log("Timer Triggered."); | |
if(target.enabled) { | |
target.Close(); | |
} | |
else { | |
target.Open(); | |
} | |
TimeLeft = 3.0f; | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment