LSBUGPG / UnityLibrary

A library of useful Unity components and test scenes
GNU General Public License v3.0
0 stars 0 forks source link

Select a unit #98

Open JammieDodgers opened 7 years ago

JammieDodgers commented 7 years ago

using UnityEngine; using System.Collections;

public class Interactive : MonoBehaviour {

private bool _Selected = false;

public bool Selected { get { return _Selected; } }

public bool Swap = false;

public void Select()
{
    _Selected = true;
    foreach (var selection in GetComponents<Interaction>()) {
        selection.Select();
    }
}

public void Deselect()
{
    _Selected = false;
    foreach (var selection in GetComponents<Interaction>()) {
        selection.Deselect();
    }
}

// Use this for initialization
void Start () {

}

// Update is called once per frame
void Update () {
    if (Swap) {
        Swap = false;
        if (_Selected) Deselect();
        else Select ();
    }
}

}

JammieDodgers commented 7 years ago

using UnityEngine; using System.Collections;

public class Highlight : Interaction {

public GameObject DisplayItem;

public override void Deselect ()
{
    DisplayItem.SetActive (false);
}

public override void Select ()
{
    DisplayItem.SetActive (true);
}

// Use this for initialization
void Start () {
    DisplayItem.SetActive (false);
}

}

JammieDodgers commented 7 years ago

using UnityEngine; using System.Collections;

public abstract class Interaction : MonoBehaviour {

public abstract void Select();
public abstract void Deselect();

}