Beruflich Dokumente
Kultur Dokumente
using UnityEngine;
using System.Collections;
void Start () {
if(startActive){
SetActive();
}
else{
SetInactive();
}
}
void SetActive(){
float duration = activeDuration;
isActive = true;
spike.gameObject.SetActive(true);
if(randomize){
duration = Random.Range(activeDuration * .25f,
activeDuration * 1.25f);
}
Invoke("SetInactive",duration);
}
void SetInactive(){
float duration = activeDuration;
isActive = false;
spike.gameObject.SetActive(false);
if(randomize){
duration = Random.Range(inactiveDuration * .25f,
inactiveDuration * 1.25f);
}
Invoke("SetActive",duration);
}
public bool GetStatus(){
return isActive;
}
}
forest fantasy.
using UnityEngine;
using System.Collections;
/// <summary>
/// The sprite used for the on toggle setting
/// </summary>
public Sprite OnSprite;
/// <summary>
/// The sprite used for the off toggle setting
/// </summary>
public Sprite OffSprite;
/// <summary>
/// The time between animation changes
/// </summary>
private float Timer = 0.0f;
/// <summary>
/// A toggle for turning this tiles functionality on or off
/// </summary>
//
public enum TOGGLE
{
ON = 0,
OFF = 1,
}
public TOGGLE Toggle;
/// <summary>
/// The time the trap takes to activate
/// </summary>
public float TrapTime = 2.0f;
#endregion
void Start ()
{
// use the initial inspector setting to determine the starting
phase of this object
sprite = gameObject.GetComponent<SpriteRenderer>();
if(Toggle == TOGGLE.OFF)
{
sprite.sprite = OffSprite;
gameObject.GetComponent<Collider2D>().enabled = false;
}
else if(Toggle == TOGGLE.ON)
{
sprite.sprite = OnSprite;
gameObject.GetComponent<Collider2D>().enabled = true;
}
}
void Update()
{
// Update the timer with the elapsed time
Timer += Time.deltaTime;
/// <summary>
/// Used to toggle between object states
/// </summary>
public void ToggleObject()
{
if(Toggle == TOGGLE.OFF)
{
// turn it on
Toggle = TOGGLE.ON;
// change the sprite to an on trigger
sprite.sprite = OnSprite;
gameObject.GetComponent<Collider2D>().enabled = true;
}
else if(Toggle == TOGGLE.ON)
{
// turn it off
Toggle = TOGGLE.OFF;