I have no idea how to write in C#, so forgive me if this is obvious. I am working through this tutorial on 2D games in Unity, and I have a problem with the code in step six. Any ideas on what's wrong?
Code:
using UnityEngine;
using System.Collections;

public class RobotController : MonoBehaviour {
   //This will be our maximum speed as we will always be multiplying by 1
   public float maxSpeed = 2f;
   //a boolean value to represent whether we are facing left or not
   bool facingLeft = true;
   //a value to represent our Animator
   Animator anim;
   // Use this for initialization
   void Start () {
      //set anim to our animator
      anim = GetComponent<Animator>();

   }

   // Update is called once per frame
   void FixedUpdate () {

      float move = Input.GetAxis ("Horizontal");//Gives us of one if we are moving via the arrow keys
      //move our Players rigidbody
      rigidbody2D.velocity = new Vector3 (move * maxSpeed, rigidbody2D.velocity.y);             //Error is on this line
      //set our speed
      anim.SetFloat ("Speed",Mathf.Abs (move));
      //if we are moving left but not facing left flip, and vice versa
      if (move < 0 && !facingLeft) {

         Flip ();
      } else if (move > 0 && facingLeft) {
         Flip ();
      }
   }

   //flip if needed
   void Flip(){
      facingLeft = !facingLeft;
      Vector3 theScale = transform.localScale;
      theScale.x *= -1;
      transform.localScale = theScale;
   }
}


The error it gives is this: UnityEngine.Component' does not contain a definition for `velocity' and no extension method `velocity' of type `UnityEngine.Component' could be found. Are you missing an assembly reference?'
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 1
» All times are UTC - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement