Question by
smartass01 · Oct 11, 2017 at 01:14 PM ·
unity 5variablescripting beginner
explain me the script
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[RequireComponent(typeof(Snake))]
public class SnakeController: MonoBehaviour {
public GameObject SnakePrefab;
public Snake head;
public Snake tail;
public int NESW;
public Vector2 nextPos;
void Start()
{
}
private void FixedUpdate()
{
Movement();
}
public void Movement()
{
GameObject temp;
nextPos = head.transform.position;
switch (NESW)
{
case 0:
nextPos = new Vector2(nextPos.x, nextPos.y + 1);
break;
case 1:
nextPos = new Vector2(nextPos.x + 1, nextPos.y);
break;
case 2:
nextPos = new Vector2(nextPos.x, nextPos.y - 1);
break;
case 3:
nextPos = new Vector2(nextPos.x - 1, nextPos.y);
break;
}
temp = (GameObject)Instantiate(SnakePrefab, nextPos, transform.rotation);
}
}
there are 2 scripts namely "snake" and "game controller". snake contains nothing. and the following script is "GameController". there are 4 things in the hierarchy. they are camera, directional light, a snake block and an empty gameobject namely "GameController". game controller script is attached to gamecontroller empty object. and snake script is attached to the snake. Please tell me why in the gamecontroller script we have made a var of script type? how does it benefit? Basically what is "public Snake head;"?
Comment
Your answer
Follow this Question
Related Questions
Cant change variable speed in script 1 Answer
How to recreate a puzzle like this. 0 Answers
How Can I Reset Values?(Unity3D) 0 Answers