Hello, I am fairly new to the c# language and and programming in general and I am having trouble with a piece of code. This one to be precise.
using UnityEngine;
using System.Collections;
public class Walker : MonoBehaviour {
//Storing the reference to RagePixelSprite -component
private IRagePixel ragePixel;
public TTA_Coord coord;
//enum for character state
public enum WalkingState {Standing=0, WalkRight, WalkLeft};
public WalkingState state = WalkingState.Standing;
//walking speed (pixels per second)
public float walkingSpeed = 10f;
void Start () {
ragePixel = GetComponent<RagePixelSprite>();
}
void Update () {
//Check the keyboard state and set the character state accordingly
Walker();
Vector3 moveDirection = new Vector3();
switch (state)
{
case(WalkingState.Standing):
//Reset the horizontal flip for clarity
ragePixel.SetHorizontalFlip(false);
ragePixel.PlayNamedAnimation("STAY", false);
break;
case (WalkingState.WalkLeft):
//Flip horizontally. Our animation is drawn to walk right.
ragePixel.SetHorizontalFlip(true);
//PlayAnimation with forceRestart=false. If the WALK animation is already running, doesn't do anything. Otherwise restarts.
ragePixel.PlayNamedAnimation("WALK", false);
//Move direction. X grows right so left is -1.
moveDirection = new Vector3(-1f, 0f, 0f);
break;
case (WalkingState.WalkRight):
//Not flipping horizontally. Our animation is drawn to walk right.
ragePixel.SetHorizontalFlip(false);
//PlayAnimation with forceRestart=false. If the WALK animation is already running, doesn't do anything. Otherwise restarts.
ragePixel.PlayNamedAnimation("WALK", false);
//Move direction. X grows right so left is +1.
moveDirection = new Vector3(1f, 0f, 0f);
break;
}
//Move the sprite into moveDirection at walkingSpeed pixels/sec
transform.Translate(moveDirection * Time.deltaTime * walkingSpeed);
}
public Walker(int TTA_Coord coord)
{
this.coord = new coord.x();
if (Input.GetKey(KeyCode.LeftArrow))
{
state = WalkingState.WalkLeft;
}
else if (Input.GetKey(KeyCode.RightArrow))
{
state = WalkingState.WalkRight;
}
else
{
state = WalkingState.Standing;
}
}
}
I cant seem to reference my other class “TTA_Coord” Properly. All I need from TTA_Coord is the integers x y and z that are being updated at run time to be output to my component script “Walker”. But ALAS I cannot find a way to do so! Any help would be gladly appreciated. The error is specifically at line 59. Thanks bunches,
TheIronHobo