-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPlay.cs
41 lines (36 loc) · 1.35 KB
/
Play.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
public class Play : MonoBehaviour
{
public float rayLenght;
public LayerMask layermask;
public Animator anim;
bool counter = true;
void Start() {
}
public void Update() {
if (Input.touchCount > 0 && Input.touches[0].phase == TouchPhase.Began) //touch input detected
{
RaycastHit hit;
Ray ray = Camera.main.ScreenPointToRay(Input.GetTouch(0).position);
if (Physics.Raycast(ray, out hit, rayLenght, layermask)) //if we hit something:
{
Debug.Log(hit.collider.name); //log the name of the hit object
string objectName = hit.collider.name;
if (objectName == "Plant" && counter == true) //start animation if Plant is hit
{
Debug.Log("plant is hit");
anim.Play("Grow");
counter = false;
} else if (objectName == "Plant" && counter == false) //stop animation on every 2th touch
{
Debug.Log("back to default");
anim.Play("Default");
counter = true;
}
}
}
}
}