- Home /
Trouble with rotating/flipping textures
Hello there! I have a character on my screen as a texture attached to a plane and have made it so when you press the arrow keys the direction of the gravity changes. So I want the character's texture to rotate/flip accordingly, so it looks like the character is standing on the walls. I've successfully flipped the textures for the Up and Down arrows as it was just a simple reverse, but can't figure out how to get it to work for left and right, because transform.Rotate does exactly what I want but it means that if the player keeps pressing the Left button for example when the gravity is already set to left, the texture will keep rotating when I want it only to rotate once. I'm probably missing something super obvious but I hope this is making sense! Below is the script I have. Please talk in C# terms as I don't understand Javascript.
Any help is appreciated. Thanks!
using UnityEngine;
using System.Collections;
public class GravitySwitch : MonoBehaviour {
void Update ()
{
if (Input.GetKeyDown(KeyCode.UpArrow))
{
Physics.gravity = new Vector3(0, 5.0F, 0);
renderer.material.SetTextureScale("_MainTex", new Vector2(1,-1));
}
if (Input.GetKeyDown(KeyCode.DownArrow))
{
Physics.gravity = new Vector3(0, -5.0F, 0);
renderer.material.SetTextureScale("_MainTex", new Vector2(1,1));
}
if (Input.GetKeyDown(KeyCode.LeftArrow))
{
Physics.gravity = new Vector3(-5.0F, 0, 0);
}
if (Input.GetKeyDown(KeyCode.RightArrow))
{
Physics.gravity = new Vector3(5.0F, 0, 0);
}
}
}