- Home /
Android 2D Character Controller
Hi all,
Here i have a simple character controller script that attaches to a gui texture. The texture being a left arrow and a right one. Two seperate gui textures.
I have tried countless times to add the character as a variable in this but everytime i get a error flagged. If someone could help me out that would be brilliant!
public class Movement : MonoBehaviour {
public Texture2D button1;
public Texture2D button2;
//public GameObject Player; <--------nothing wrong here i don't think
void Start ()
{
guiTexture.texture = button1;
}
void Update ()
{
foreach (Touch touch in Input.touches)
{
if (guiTexture.HitTest(touch.position) && touch.phase != TouchPhase.Ended)
{
guiTexture.texture = button2;
transform.Translate(Vector3.right * 30 * Time.smoothDeltaTime);
}
else if (guiTexture.HitTest(touch.position) && touch.phase == TouchPhase.Ended)
{
guiTexture.texture = button1;
}
}
}
}
OK I have implemented a solution. I forgot to add the 'Player' in front of the transform here is the amended line of code for anyone else who wants to use it :) no problems with anyone using it by the way.
Player.transform.Translate(Vector3.right * 30 * Time.smoothDeltaTime);
Answer by corriedotdev · Mar 18, 2014 at 11:09 PM
I have an idea where to go and mark this as answered. Thanks mod :)
You should let us know what exaclty did you do to fix your problem in case another user has to deal with the same issue.
Answer by koray1396 · Mar 18, 2014 at 09:56 PM
Have you tried another variable name than "character"? It can cause errors since it is pre-defined for keyboard chars.
The name character should be irrelevant, its the code after that which transforms the location of the character itself im having trouble with.
Your answer
Follow this Question
Related Questions
How to make an object follow the player? 2 Answers
not sure how to use 2d sprites for my problem. 1 Answer
After exporting my game stopped working 0 Answers
How to apply explosion prefab to an object upon collision 2 Answers
Unity android bluetooth controller disconnect doesn't make array empty 1 Answer