Question by
Vicodi · Nov 07, 2020 at 10:47 AM ·
speedaccelerationsnakespeed up
accelerate speed
so am making a snake game, and i want the snake's speed to accelerate after eating 5 apples then after eating 10 and after 20 and 40 apples.
public class Snake : MonoBehaviour
{
public float speed = 0.2f;
Vector2 dir = Vector2.left;
// keeps track of tail
List<Transform> tail = new List<Transform>();
//did the snake eat
bool ate = false;
//the tail's prefab
public GameObject tailPrefab;
void Start()
{
InvokeRepeating("Move", 2f, speed);
}
void Move()
{
//this saves the position of the last tail i the form of vector2 v
Vector2 v = transform.position;
if (ate)
{
// Load Prefab into the world
GameObject g =(GameObject)Instantiate(tailPrefab,
v,
Quaternion.identity);
// Keep track of it in our tail list
tail.Insert(0, g.transform);
// Reset the flag
ate = false;
}
else if (tail.Count > 0)
{
//moves last tail into wher the head was
tail.Last().position = v;
//add to front of list , remove from back
tail.Insert(0,tail.Last());
tail.RemoveAt(tail.Count-1);
}
}
Comment
Your answer
Follow this Question
Related Questions
InvokeRepeating not working 1 Answer
Stuck on a project, need help with mechanics 0 Answers
How to include speed trigger creation option in this script. 0 Answers
How to get static speed 1 Answer
Speed pad/booster 3D 1 Answer