Beispiel #1
0
    // Update is called once per frame
    void Update()
    {
        Vector3      mousePos   = Camera.main.ScreenToWorldPoint(Input.mousePosition);
        Vector2      mousePos2D = new Vector2(mousePos.x, mousePos.y);
        RaycastHit2D hit        = Physics2D.Raycast(mousePos2D, Vector2.zero);


        // check if collider is not a null
        if (hit.collider != null)
        {
            // if hovering over a minion
            if (hit.collider.gameObject.tag == "Minion" && hit.collider.gameObject.GetComponent <MinionTarget>().hired == false && holeController.candy >= hirePrice)
            {
                Cursor.SetCursor(cursorMinion, hotSpot, cursorMode);
                if (Input.GetMouseButtonDown(0))
                {
                    // get component of the minion clicked and make them hired
                    MinionTarget minionController = hit.collider.gameObject.GetComponent <MinionTarget>();
                    minionController.hired = true;
                    holeController.candy  -= hirePrice;
                    if (minionController.status == "hostage")
                    {
                        minionController.status = "roam";
                        minionController.changeTargets();
                    }
                    Debug.Log("Minion: " + hit.collider.gameObject.name + " is now hired");
                }
            }
            else if (hit.collider.gameObject.tag == "Enemy")
            {
                Cursor.SetCursor(cursorEnemy, hotSpot, cursorMode);
                if (Input.GetMouseButtonDown(0))
                {
                    MainControllerScript controller = GameObject.Find("MainCharacter").GetComponent <MainControllerScript>();
                    if (controller != null)
                    {
                        controller.launchProjectile(mousePos2D);
                    }
                }
            }
            else if (hit.collider.gameObject.tag == "Bowl" && hit.collider.gameObject.GetComponent <CandyBowlController>().collectable == true)
            {
                // bowl cursor
                Debug.Log("Mouse On Bowl");
                Cursor.SetCursor(cursorBowl, hotSpot, cursorMode);
                if (Input.GetMouseButtonDown(0))
                {
                    hit.collider.gameObject.GetComponent <CandyBowlController>().collectCandy();
                    GameObject.Find("MainCharacter").GetComponent <MainControllerScript>().playClip(clip);
                    Cursor.SetCursor(cursorDefault, hotSpot, cursorMode);
                }
            }
        }
        else
        {
            // default cursor
            Cursor.SetCursor(cursorDefault, hotSpot, cursorMode);
        }
    }
    /// <summary>
    /// Loads all the modules.
    /// </summary>
    void Awake()
    {
        if (instance != null)
        {
            Destroy(gameObject);
            return;
        }

        DontDestroyOnLoad(transform.gameObject);
        instance  = this;
        battleGUI = GetComponent <BattleGUIController>();
        StartCoroutine("WaitForInitiate");
    }
Beispiel #3
0
 void OnTriggerEnter2D(Collider2D other)
 {
     if (other.tag == "HostageZone")
     {
         // go back to roaming
         if (status == "flee")
         {
             Destroy(gameObject);
         }
         Invoke("roam", 5.0f);
     }
     else if (other.tag == "Projectile")
     {
         changeHealth(-5.0f);
     }
     else if (other.tag == "MainCharacter")
     {
         MainControllerScript controller = other.gameObject.GetComponent <MainControllerScript>();
         if (controller != null)
         {
             controller.changeHealth(-5.0f);
         }
     }
 }