# PlayerController.cs V0

## Simple PlayerController: Version 0&#x20;

This first example script connects user keyboard input with changes in Animator animationState.  There is no logic to move the gameObject, or change values of the Transform Position vector values: x, y, z.

Simple Script to connect key-input to Animator Parameter: "HeroState".

```java
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PlayerController : MonoBehaviour
{
    //create custom data-type
    public enum HeroState { idle = 0, walk = 1, jump = 2} //custom data-type 
    public HeroState currentHeroState;  //variable to keep track of current animation state

    private bool facingRight = true; // initialize when declare (first way),  false by default

    private Animator animator; //obj-reference variable to access the animator component on this gameObject

    //inspector is the second way to initialize a value

    // Start is called before the first frame update
    private void Start()
    {
        facingRight = true; //final way to initialize, overrides all prior settings
        animator = GetComponent<Animator>(); //<T>  //call a method - make connection to component on gameObject in Unity scene
        animator.SetInteger( "HeroState",  (int) HeroState.idle      );
    }

    //Fixed update used for physics, to give smooth motion, called at consistent time increments
    void FixedUpdate()
    {
        float inputX = Input.GetAxis("Horizontal"); // key input:  -1, 0, 1
        bool isWalking = Mathf.Abs(inputX) > 0;

        //check for spacebar or w, up keys to indicate vertical jump
        bool jumpPressed = Input.GetButtonDown("Jump") || Input.GetAxis("Vertical") > 0;


        if (isWalking)
        {
            animator.SetInteger("HeroState", (int)HeroState.walk);
        }
        else
        {
            animator.SetInteger("HeroState", (int)HeroState.idle);
        }


        if (jumpPressed)
        {
            animator.SetInteger("HeroState", (int)HeroState.jump);
        }

    }


}  //end class PlayerController
```

##


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://kdoore.gitbook.io/cs2335/f20_bkup_v2/animation/playercontroller.cs-v0.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
