Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialAyush Bhargava
791 Pointsfrog won't move forward
My frog has a problem of moving forward at the ned of this video There is a yellow error which says the refrenced script on there behavior is missing. This is my code
using UnityEngine;
using System.Collections;
public class PlayerMovement : MonoBehaviour {
private Animator playerAnimator;
private float moveHorizontal;
private float moveVertical;
private Vector3 movement;
// Use this for initialization
void Start () {
playerAnimator = GetComponent<Animator> () ;
}
// Update is called once per frame
void Update () {
moveHorizontal = Input.GetAxisRaw ("Horizanatal");
moveVertical = Input.GetAxisRaw ("Vertical");
movement = new Vector3 (moveHorizontal, 0.0f, moveVertical);
}
void FixedUpdate () {
if (movement != Vector3.zero) {
playerAnimator.SetFloat ("Speed", 3f);
} else {
playerAnimator.SetFloat ("Speed", 0f);
}
}
}
4 Answers
Daniel Hartin
18,106 PointsHi Ayush
It looks like a simple typo to me, try looking at the spelling of Horizontal in your update() method as per the below
using UnityEngine;
using System.Collections;
public class PlayerMovement : MonoBehaviour {
private Animator playerAnimator;
private float moveHorizontal;
private float moveVertical;
private Vector3 movement;
// Use this for initialization
void Start () {
playerAnimator = GetComponent<Animator> () ;
}
// Update is called once per frame
void Update () {
moveHorizontal = Input.GetAxisRaw ("Horizontal");
moveVertical = Input.GetAxisRaw ("Vertical");
movement = new Vector3 (moveHorizontal, 0.0f, moveVertical);
}
void FixedUpdate () {
if (movement != Vector3.zero) {
playerAnimator.SetFloat ("Speed", 3f);
} else {
playerAnimator.SetFloat ("Speed", 0f);
}
}
}
I've not tested the update, let me know if it doesn't work
Daniel
Ayush Bhargava
791 PointsThanks,Daniel It fixed my other small errors but the main errors as i said above is still a problem "the refrenced script on this behavior is missing"
micram1001
33,833 Pointshi, on the Macintosh version of Unity, the PlayerMovement script is added automatically to the inspector as show on the video at minute 11:47. On the Windows, I had to drag the PlayerMovement script to the Inspector to make the Frog jump. Hope this helps.
Jon Sonneborn
322 PointsI have the same issue, Any solution?
using UnityEngine; using System.Collections;
public class PlayerMovement : MonoBehaviour {
private Animator playerAnimator;
private float moveHorizontal;
private float moveVertical;
private Vector3 movement;
// Use this for initialization
void Start () {
playerAnimator = GetComponent<Animator> () ;
}
// Update is called once per frame
void Update () {
moveHorizontal = Input.GetAxisRaw ("Horizontal");
moveVertical = Input.GetAxisRaw ("Vertical");
movement = new Vector3 (moveHorizontal, 0.0f, moveVertical);
}
void FixedUpdate () {
if (movement != Vector3.zero) {
playerAnimator.SetFloat ("Speed", 3f);
} else {
playerAnimator.SetFloat ("Speed", 0f);
}
}
}
viktor Degerman
3,056 Pointsyou need one more } playerAnimator.SetFloat ("Speed", 0f); } } }
Daniel Hartin
18,106 PointsDaniel Hartin
18,106 PointsOk sorry that didn't work I'm unsure how far you have got in the videos but the lines of your code do match what I've got in my scripts (below), I have completed the game development course though so it may include sections you haven't covered yet;
Sorry I can't be of more help but I'm still a novice with Unity myself, by all means create a new script and play around with the code below to see if you can get it to work in your game
Daniel