I am newbie on Unity 3d.I have started practising with a snake game. I have to move snake head forward first.If i press any key then the snake should start moving ahead.For its head i have taken simply a cube. Here is the code. Please tell me where i am doing mistake.
public class SnakeMove: MonoBehaviour {
public bool Move_Up;
public bool Move_Below ;
public bool Move_Right;
public bool Move_Left;
public body first_body;
public float time_movement = .5F;
public float following_movement;
// Use this for initialization
void Start () {
Move_Up = false;
Move_Below = false;
Move_Right = false;
Move_Left= false;
following_movement = Time.time + time_movement;
}
// Update is called once per frame
void Update () {
if (Input.GetKeyDown(KeyCode.UpArrow))
{
Move_Up = true;
Move_Below = false;
Move_Right = false;
Move_Left = false;
}
if (Input.GetKeyDown(KeyCode.DownArrow))
{
Move_Up = false;
Move_Below = true;
Move_Right = false;
Move_Left = false;
}
if (Input.GetKeyDown(KeyCode.RightArrow))
{
Move_Up = false;
Move_Below = false;
Move_Right = true;
Move_Left = false;
}
if (Input.GetKeyDown(KeyCode.LeftArrow))
{
Move_Up = false;
Move_Below = false;
Move_Right = false;
Move_Left = true;
}
if (Time.time > following_movement)
{
MoveHead();
}
}
void MoveHead()
{
if (Move_Up)
{
first_body.move(this.transform);
this.transform.position += transform.forward *transform.localScale.z;
}
if (Move_Below)
{
first_body.move(this.transform);
this.transform.position += -transform.forward * transform.localScale.z;
}
if (Move_Right)
{
first_body.move(this.transform);
this.transform.position += transform.right * transform.localScale.z;
}
if (Move_Left)
{
first_body.move(this.transform);
this.transform.position += -transform.right * transform.localScale.z;
}
following_movement = Time.time + time_movement;
}
}
The error is:
Assets/Scripts/SnakeMotion.cs(92,8): error CS0246: The type or namespace name `body’ could not be found. Are you missing a using directive or an assembly reference?
Should have I to make a body script also? N what should be included in that script? Or Can i run without making separate Body script also? Sorry for my english.