-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpieClownScript.cs
More file actions
122 lines (98 loc) · 2.77 KB
/
Copy pathpieClownScript.cs
File metadata and controls
122 lines (98 loc) · 2.77 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
using UnityEngine;
using System.Collections;
public class pieClownScript : MonoBehaviour {
public float distance;
public Vector3 direction;
public float shootForce;
public Transform pie;
public bool throwingPie;
public float timer;
public int health;
public int hitByPlayerDamage;
public float hitTimer;
public GameObject player;
public float moveSpeed;
public Transform graphic;
public playerScript playerComp;
public int directionFace;
// Use this for initialization
void Start () {
//base.Start();
player = GameObject.FindGameObjectWithTag("Player");
playerComp = player.GetComponent<playerScript>();
graphic = transform.GetChild(0);
throwingPie = false;
timer = 0;
health = 3;
hitByPlayerDamage = 1;
hitTimer = 0;
}
void OnCollisionEnter (Collision col)
{
if (col.gameObject.tag == "Shield")
{
player.GetComponent<playerScript>().messiness += player.GetComponent<playerScript>().hurtDamage;
health -= hitByPlayerDamage;
}
}
void Update(){
//if (graphic.GetComponent<Animator>().GetBool("Throwing"))
//
if (player.transform.position.x > transform.position.x)
directionFace = -1;
else
directionFace = 1;
graphic.transform.localScale = new Vector3(Mathf.Abs(graphic.transform.localScale.x) * directionFace, graphic.transform.localScale.y, graphic.transform.localScale.z);
graphic.GetComponent<SpriteRenderer>().renderer.sortingOrder = (int)(transform.position.y * 100 * -1);
if (player.GetComponent<playerScript>().dirtiness != 3)
{
if (Time.time - timer > 1f)
throwPie ();
}
}
// Update is called once per frame
void FixedUpdate () {
//base.Update();
if (health <= 0)
{
Destroy(gameObject);
return;
}
distance = Vector3.Distance(transform.position, player.transform.position);
if(throwingPie)
{
throwingPie = false;
waitSeconds(.1429f);
}
//if(graphic.animation.IsPlaying("pieth row"))
//{
if (distance > 2.1f)
{
transform.position = Vector3.MoveTowards(transform.position, player.transform.position, moveSpeed * Time.deltaTime);
}
else if (distance < 2f)
{
// direction = transform.position - player.transform.position;
// direction.Normalize();
transform.position = Vector3.MoveTowards(transform.position, player.transform.position, -moveSpeed * Time.deltaTime);
}
//}
}
void throwPie()
{
timer = Time.time;
throwingPie = true;
graphic.GetComponent<Animator>().SetTrigger("Throw");
graphic.GetComponent<Animator>().SetBool("Throwing", true);
StartCoroutine(waitSeconds(.1429f * 2));
}
void pieCoolDown()
{
graphic.GetComponent<Animator>().SetBool("Throwing", false);
}
IEnumerator waitSeconds (float seconds)
{
yield return new WaitForSeconds(seconds);
Instantiate(pie, transform.position, transform.rotation);
}
}