Hello Im new in Unity.I am going to develop a game. There is two sprite in my game window, one is top other is bottom and they are randomly looped. when I touch the top sprite it will execute a action and if I touch lower portion it will not work. Im trying but there is a problem when I touch in top or bottom it always execute the action. How can I turn off the executing action in bottom??
I want the didFlap(in below code) will true only when the top portion is clicked/touched.
using UnityEngine;
using System.Collections;
public class BirdMovement : MonoBehaviour {
public float flapSpeed = 100f;
public float forwardSpeed = 1f;
bool didFlap = false;
Animator animator;
public bool dead = false;
float deathCooldown;
public bool godMode = false;
public GameObject gameEndmessage;
public AudioClip flapSound;
public AudioClip hitSound;
public static bool soundPlay = true;
// Use this for initialization
void Start () {
animator = transform.GetComponentInChildren<Animator>();
if(animator == null) {
Debug.LogError("Didn't find animator!");
}
}
// Do Graphic & Input updates here
void Update() {
if(!didFlap){
if (Input.GetKeyDown(KeyCode.Escape))
Application.LoadLevel(0);
}
if(dead) {
deathCooldown -= Time.deltaTime;
if(deathCooldown <= 0) {
if (Input.GetKeyDown(KeyCode.Escape))
Application.LoadLevel(0);
if(Input.GetKeyDown(KeyCode.Space) || Input.GetMouseButtonDown(0) ) {
//Application.LoadLevel( Application.loadedLevel );
}
}
}
else {
if(Input.GetKeyDown(KeyCode.Space) || Input.GetMouseButtonDown(0) ) {
didFlap = true;
}
}
}
// Do physics engine updates here
void FixedUpdate () {
if(dead)
return;
rigidbody2D.AddForce( Vector2.right * forwardSpeed );
if(didFlap) {
rigidbody2D.AddForce( Vector2.up * flapSpeed );
animator.SetTrigger("DoFlap");
if(soundPlay){
audio.clip=flapSound;
audio.Play ();
}
didFlap = false;
}
if(rigidbody2D.velocity.y > 0) {
transform.rotation = Quaternion.Euler(0, 0, 0);
}
else {
float angle = Mathf.Lerp (0, -90, (-rigidbody2D.velocity.y / 3f) );
transform.rotation = Quaternion.Euler(0, 0, angle);
}
}
void OnCollisionEnter2D(Collision2D collision) {
//Debug.Log("Yes Bird Down");
if(godMode)
return;
if(soundPlay){
audio.clip=hitSound;
audio.Play ();
}
animator.SetTrigger("Death");
dead = true;
deathCooldown = 0.5f;
gameEndmessage.SetActive (true);
}
void SoundButton(){
if (soundPlay) {
soundPlay = false;
} else {
soundPlay=true;
}
}
void GameRestart(){
Application.LoadLevel(1);
}
}