예제 #1
0
 // Update is called once per frame
 void Update()
 {
     if (hub.findCharacterAt(transform.position) == hub.cursor.selectedCharacter)
     {
         GameObject.DestroyObject(this);
     }
 }
예제 #2
0
    //used to move the cursor
    void DetectMovement()
    {
        //mv shows where the cursor has moved to. This is so I can move the camera with the cursor
        Vector3 mv = new Vector3(0, 0, 0);

        //Each key only gives input every tenth of a second. This keeps the cursor
        //moving smoothley

        //up
        if (Input.GetKey(KeyCode.UpArrow) && Time.time - hub.lastTimeUp >= 0.1f)
        {
            hub.lastTimeUp = Time.time;
            mv             = new Vector3(0, spacer, 0);
        }
        //down
        if (Input.GetKey(KeyCode.DownArrow) && Time.time - hub.lastTimeDown >= 0.1f)
        {
            hub.lastTimeDown = Time.time;
            mv = new Vector3(0, -1 * spacer, 0);
        }
        //right
        if (Input.GetKey(KeyCode.RightArrow) && Time.time - hub.lastTimeRight >= 0.1f)
        {
            hub.lastTimeRight = Time.time;
            mv = new Vector3(spacer, 0, 0);
        }
        //left
        if (Input.GetKey(KeyCode.LeftArrow) && Time.time - hub.lastTimeLeft >= 0.1f)
        {
            hub.lastTimeLeft = Time.time;
            mv = new Vector3(-1 * spacer, 0, 0);
        }

        //for confirm and cancel, I wait a bit longer between inputs to help stop the game
        //from canceling and confirming between menus. Sometimes this can be noticable, but hardly..

        //on confirm
        if (Input.GetKeyDown(KeyCode.Z) && Time.time - hub.lastTimeZ >= 0.25f)
        {
            hub.lastTimeZ = Time.time;

            //if you have not selected a character, do so
            if (canSelect && !summoning && !attacking)
            {
                DetectSelect();
            }

            //if the character hits confirm, check if there is a summon tile, if so, place the unit there
            else if (summoning)
            {
                if (isOnTile("SummonTile"))
                {
                    canSelect = true;
                    summoning = false;
                    hub.RemoveTiles("SummonTile");
                    selectedCharacter = null;
                }
            }
            //if the player is currently trying to select an attack target
            else if (attacking)
            {
                if (isOnTile("EnemyTile"))
                {
                    canSelect = true;
                    attacking = false;
                    hub.RemoveTiles("EnemyTile");
                    //print(fightingCharacter.name);
                    fightingCharacter.fight(hub.findCharacterAt(transform.position));
                    confirmFromMoveMenu();
                }
            }
            //if you have a character selected, give them options from this point
            else if (isOnTile("MoveTile"))
            {
                GoToMoveMenu();
            }
        }

        //on cancel
        if (Input.GetKeyDown(KeyCode.X) && Time.time - hub.lastTimeX >= 0.25f && !summoning)
        {
            hub.lastTimeX = Time.time;
            if (!canSelect)
            {
                selectedCharacter.transform.position = new Vector3(charOrgX, charOrgY, 0);
            }
            if (selectedCharacter != null)
            {
                selectedCharacter = null;
            }
            canSelect = true;

            //remove the extra tiles
            hub.RemoveTiles("MoveTile");
            hub.RemoveTiles("EnemyTile");
            hub.RemoveTiles("SummonTile");
        }

        hub.cam.moveCamera(transform.position + mv);
        transform.position += mv;
    }