-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAnimTriggerHandler.cs
More file actions
66 lines (57 loc) · 1.76 KB
/
AnimTriggerHandler.cs
File metadata and controls
66 lines (57 loc) · 1.76 KB
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class AnimTriggerHandler : MonoBehaviour
{
public Animator animator; // Reference to the Animator
private int c = 0; // Counter for enabling/disabling Animator
private int t = 0; // Counter for setting 'state' parameter
private int a = 0;
void Start()
{
if (animator == null)
animator = GetComponent<Animator>();
// Set default state to 1 at start
animator.SetTrigger("set1");
}
private void OnTriggerEnter(Collider other)
{
if (other.CompareTag("AnimTrig"))
{
c++; // Increment enable/disable counter
t++; // Increment state counter
if (t % 2==0)
{
a++;
}
// Toggle Animator component
if (c % 2 != 0)
{
animator.enabled = false;
Debug.Log("Animator Disabled (c=" + c + ")");
}
else
{
animator.enabled = true;
if (a % 2 != 0)
{
animator.Play("tilt1 1");
}
else
{
animator.Play("tilt1");
}
Debug.Log("Animator Enabled (c=" + c + ")");
}
// Set state parameter
/*if (t % 2 != 0)
{
animator.SetTrigger("set1");
}
else
{
animator.SetTrigger("set2");
}**/
}
}
}