UnityGameProjectsCode / RelianceGame / Mouse Control / MouseOverBot.cs
MouseOverBot.cs
Raw
using MouseTools;
using UnityEngine;

public class MouseOverBot : MonoBehaviour //placed on bots with a bool manaully set to tell the cursor what icon to switch to
{
    private CustomCursor mouseController;
    private PlayerCallForHelp pCall;
    public bool greenBot;
    public bool blueBot;
    public bool orangeBot;
    public bool leadBot;
    public bool enemyBot;

    private void Start()
    {
        mouseController = GameObject.Find("RunningUI/Mouse Base").GetComponent<CustomCursor>();

        if (leadBot)
            pCall = GetComponent<PlayerCallForHelp>();
    }

    private void Update()
    {
        if (leadBot)
        {
            GameObject enemy = pCall.GetEnemy();

            if (enemy == null && mouseController.overBot == true && mouseController.overEnemy == true)
            {
                mouseController.overBot = false;
                mouseController.ChangeCursor(5);
                mouseController.overEnemy = false;
            }
        }
    }

    private void OnMouseEnter()
    {
        if (!mouseController.botSelected)
        {
            setCursor();
        }

        if (enemyBot)
            mouseController.overEnemy = true;
        else
            mouseController.overBot = true;
    }

    private void OnMouseExit()
    {
        if (mouseController.botSelected == false)
        {
            mouseController.overBot = false;
            mouseController.ChangeCursor(5);
        }
        else
        {
            mouseController.overBot = false;
        }

        if (enemyBot)
            mouseController.overEnemy = false;
        else
            mouseController.overBot = false;
    }

    public void setCursor()
    {
        if (enemyBot)
        {
            mouseController.overBot = true;
            mouseController.ChangeCursor(4);
        }
        else if (greenBot)
        {
            mouseController.overBot = true;
            mouseController.ChangeCursor(0);
        }
        else if (blueBot)
        {
            mouseController.overBot = true;
            mouseController.ChangeCursor(1);
        }
        else if (orangeBot)
        {
            mouseController.overBot = true;
            mouseController.ChangeCursor(2);
        }
        else if (leadBot)
        {
            mouseController.overBot = true;
            mouseController.ChangeCursor(3);
        }
    }

    public void SetBotTargetBool() //sets target bool in customcursor
    {
        if (enemyBot)
        {
            mouseController.enemyBot = true;
            mouseController.greenBot = false;
            mouseController.blueBot = false;
            mouseController.orangeBot = false;
            mouseController.leadBot = false;
        }
        else if (greenBot)
        {
            mouseController.enemyBot = false;
            mouseController.greenBot = true;
            mouseController.blueBot = false;
            mouseController.orangeBot = false;
            mouseController.leadBot = false;
        }
        else if (blueBot)
        {
            mouseController.enemyBot = false;
            mouseController.greenBot = false;
            mouseController.blueBot = true;
            mouseController.orangeBot = false;
            mouseController.leadBot = false;
        }
        else if (orangeBot)
        {
            mouseController.enemyBot = false;
            mouseController.greenBot = false;
            mouseController.blueBot = false;
            mouseController.orangeBot = true;
            mouseController.leadBot = false;
        }
        else if (leadBot)
        {
            mouseController.enemyBot = false;
            mouseController.greenBot = false;
            mouseController.blueBot = false;
            mouseController.orangeBot = false;
            mouseController.leadBot = true;
        }
    }

    public void SetBotAIMachine()
    {
        if (!leadBot)
            mouseController.selectedBot = GetComponent<AIMachine>();
    }
}