Пример #1
0
//This function checks what key is pressed + changes player's move state
    void CheckKey()
    {
        if (Input.GetKey(KeyCode.W))    //Up
        {
            currentState = directionState.up;
        }
        else if (Input.GetKey(KeyCode.S))      //Down
        {
            currentState = directionState.down;
        }
        else if (Input.GetKey(KeyCode.A))      //Left
        {
            currentState     = directionState.left;
            myRenderer.flipX = false;
        }
        else if (Input.GetKey(KeyCode.D))      //Right
        {
            currentState     = directionState.right;
            myRenderer.flipX = true;
        }
        else
        {
            currentState = directionState.none; //None
        }
    }
Пример #2
0
 void OnCollisionEnter2D(Collision2D other)
 {
     if (other.gameObject.tag == "LeftWall")
     {
         direction = directionState.Right;
         StartCoroutine(MoveDown());
     }
     else if (other.gameObject.tag == "RightWall")
     {
         direction = directionState.Left;
         StartCoroutine(MoveDown());
     }
 }
Пример #3
0
    private void OnLoad()
    {
        string playerToLoad = GManager.Instance.ReadNextObjectToLoad();

        _thisTransform.name     = GManager.FindStringParameterInObject(playerToLoad, "_thisTransform.name");
        _thisTransform.position = GManager.FindVector3InObject(playerToLoad, "_thisTransform.position");
        _rigidbody.velocity     = GManager.FindVector2InObject(playerToLoad, "_rigidbody.velocity");
        health          = GManager.FindFloatParamInSObject(playerToLoad, "Player.health");
        _directionState = (directionState)Enum.Parse(typeof(directionState), GManager.FindStringParameterInObject(playerToLoad, "Player._directionState", "", ""));
        _forceState     = (forceState)Enum.Parse(typeof(forceState), GManager.FindStringParameterInObject(playerToLoad, "Player._forceState", "", ""));
        _moveState      = (moveState)Enum.Parse(typeof(moveState), GManager.FindStringParameterInObject(playerToLoad, "Player._moveState", "", ""));

        _lowHealthWarning = false;
        UIPlayer.SetHealth(health);
    }
Пример #4
0
    private void DirectionSwitch(float _direction)
    {
        if (_direction != 0)
        {
            direction = _direction;
        }

        if (direction > 0)
        {
            _directionState = directionState.right;
        }
        else if (direction < 0)
        {
            _directionState = directionState.left;
        }
    }
Пример #5
0
    // Use this for initialization
    void Awake()
    {
        rb            = GetComponent <Rigidbody2D>();
        interpolation = Random.Range(5, 75);

        if (transform.position.x < 0)
        {
            direction = directionState.Right;
        }
        else
        {
            direction = directionState.Left;
        }

        StartCoroutine(AILoop());
        gamemanager = GameObject.FindGameObjectWithTag("GameController").GetComponent <GameManager>();
    }
Пример #6
0
 void CheckKey() //grabs each piece of code that moves the character depending on the key they press
 {
     if (Input.GetKey(KeyCode.W))
     {
         currentState = directionState.up;
     }
     else if (Input.GetKey(KeyCode.S))
     {
         currentState = directionState.down;
     }
     else if (Input.GetKey(KeyCode.A))
     {
         currentState = directionState.left;
     }
     else if (Input.GetKey(KeyCode.D))
     {
         currentState = directionState.right;
     }
     else
     {
         currentState = directionState.none;
         Debug.Log("No key pressed");
     }
 }