Hey,
I want to create a snake game, but the objects rotate in a way, so they won’t be displayed anymore.
The code of the controller is:
```csharp
*using UnityEngine;[/I]
[I]
using System.Collections;
using System.Collections.Generic;
using System.Linq;
public class Snake : MonoBehaviour
{
float timer;
float timelaps = 20;
int direc;
// Did the snake eat something?
bool ate = false;
float x = 0.1F;
float y = 0.1F;
public GameObject GameOver;
// Tail Prefab
public GameObject tailPrefab;
// Head Prefab
public GameObject head;
// Current Movement Direction
// (by default it moves to the right)
Vector2 dir = Vector2.down;
// Use this for initialization
void Start()
{
// Move the Snake every 300ms
//InvokeRepeating("Move",x, y);
}
// Update is called once per Frame
void Update()
{
// Move in a new Direction?
//head.transform.rotation = Quaternion.AngleAxis(30, Vector3.up);
float step = Time.deltaTime;
if (Input.GetKey(KeyCode.UpArrow) && dir != Vector2.down)
{
dir = Vector2.up;
head.transform.Rotate(Vector2.up, 90);
}
else if(Input.GetKey(KeyCode.DownArrow) && dir != Vector2.up)
{
dir = Vector2.down;
head.transform.Rotate(Vector2.down, 90);
}
else if (Input.GetKey(KeyCode.RightArrow) && dir != Vector2.left)
{
dir = Vector2.right;
head.transform.Rotate(Vector2.right, 90);
//head.transform.rotation = Quaternion.AngleAxis(30, Vector2.right);
}
else if (Input.GetKey(KeyCode.LeftArrow) && dir != Vector2.right)
{
dir = Vector2.left;
head.transform.Rotate(Vector2.left, 90);
//head.transform.rotation = Quaternion.AngleAxis(30, Vector2.left);
}
if (timer >= timelaps) {
Move();
timer = 0;
}else{
timer++;
}
}
}*
```
Here’s a screenshot of the scene:
What rotation method should I use, to rotate the sprite of the game object?
A: The rotated object
B: This is the rotation,
C: This variable needs to be rotated.
Please help me to finish the rotation
Best regards