Reputation: 1
Presently working on mobile 3D endless runner game.when press UI button my player running animation.when touch on mobile scree my player attacking animation. But here my problem is when pressed UI button both running and attack animation is played.
can any one suggest how to solve this problem
using System.Collections;
using UnityEngine.EventSystems;
public class TestAgain : MonoBehaviour
{
float lastTouchForDouble, lastTouchForMulti, presentTouchTime = 0.3f,multiTouchTime = 0.2f;
bool isTouch;
public GameObject ant;
public float zoomValue;
float deltaMagnitudeDiff;
Ray ray;
RaycastHit hit;
public float scaleFactor;
public float minScale = 0.05f;
public float maxScale = 1f;
void Update ()//!EventSystem.current.IsPointerOverGameObject(pointerId)
{
if (Input.touchCount > 0) {
foreach (Touch touch in Input.touches) {
if (EventSystem.current.IsPointerOverGameObject(touch.fingerId)){
return;
}
int pointerId = touch.fingerId;
if (touch.phase == TouchPhase.Ended) {
if (Input.touchCount == 1 && Input.touchCount != 2) {
if (!isTouch) {
isTouch = true;
ray = Camera.main.ScreenPointToRay (touch.position);
if (Physics.Raycast (ray, out hit)) {
if (hit.collider.name.Contains ("Player")) {
// Player attack animation
}
}
}
public void OnButtonClick()
{
//Play run animation
}
Upvotes: 0
Views: 264