- Home /
not able to see my character
i am new in unity. i have created a character with game object and given it some animation .i also gave some touch code to work on my android device .following is the code and the clip to my scene and game mode
using UnityEngine; using System.Collections; [RequireComponent(typeof (Rigidbody2D))] [RequireComponent(typeof(BoxCollider2D))] public class animation : MonoBehaviour { public GUITexture guiLeft; public GUITexture guiRight; public float maxspeed=10F; bool facingright=true; Animator anim; int a=1;
// Use this for initialization
void Start () {
anim = GetComponent<Animator> ();
}
// Update is called once per frame
void Update () {
if (Input.touchCount > 0)
{
Touch t=Input.GetTouch(0);
if(t.phase==TouchPhase.Began)
{
if(guiLeft.HitTest(t.position,Camera.main))
{
FixedUpdate();
}
if(guiRight.HitTest(t.position,Camera.main))
{
FixedUpdate();
}
}
if(t.phase==TouchPhase.Ended)
{
a++;
FixedUpdate();
}
}
}
void FixedUpdate()
{
if (a > 0)
{
rigidbody2D.velocity = Vector2.zero;
}
float move=Input.GetAxis("Horizontal");
anim.SetFloat ("speed", Mathf.Abs (move));
rigidbody2D.velocity = new Vector2 (move * maxspeed, rigidbody2D.velocity.y);
if (move > 0 && !facingright)
Flip ();
else if (move < 0 && facingright)
Flip ();
}
void Flip()
{
facingright = !facingright;
Vector3 thescale =transform.localScale;
thescale.x*=-1;
transform.localScale = thescale;
}
}
Your answer
Follow this Question
Related Questions
It is not possible to invoke an expression of type 'SpriteManager[]'. 1 Answer
Character Controller Collision 4 Answers
Character Animation Wont Play 2 Answers
How to make camera not rotate with player, only move 1 Answer
Player or character select 2 Answers