-
Notifications
You must be signed in to change notification settings - Fork 0
/
pieScript.cs
125 lines (95 loc) · 3.25 KB
/
pieScript.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
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
123
124
125
using UnityEngine;
using System.Collections;
public class pieScript : MonoBehaviour {
public Vector3 target;
public float moveSpeed;
public GameObject player;
public Transform graphic;
public float offset;
public bool stopped = false;
public bool reflected = false;
public bool pieFacing = false;
//public float timer = Time.time;
Animator animator;
// Use this for initialization
void Start () {
stopped = false;
reflected = false;
moveSpeed = 2f;
player = GameObject.FindGameObjectWithTag("Player");
graphic = transform.GetChild(0);
target = new Vector3(player.transform.position.x - transform.position.x, player.transform.position.y - transform.position.y, 0);
animator = GetComponentInChildren<Animator>();
if (transform.position.x - player.transform.position.x > 0)
graphic.transform.localScale = new Vector3(Mathf.Abs(graphic.transform.localScale.x) * 1, graphic.transform.localScale.y, graphic.transform.localScale.z);
else
graphic.transform.localScale = new Vector3(Mathf.Abs(graphic.transform.localScale.x) * -1, graphic.transform.localScale.y, graphic.transform.localScale.z);
if (transform.position.y - player.transform.position.y < 0)
pieFacing = true;
//graphic.GetComponent<Animator>().SetTrigger("Up");
else
pieFacing = false;
//graphic.GetComponent<Animator>().SetTrigger("Down");
}
// Update is called once per frame
void Update () {
if (pieFacing)
graphic.GetComponent<Animator>().SetTrigger("Up");
else
graphic.GetComponent<Animator>().SetTrigger("Down");
}
void FixedUpdate()
{
if (!stopped)
{
transform.Translate(target * moveSpeed* Time.deltaTime);
}
else {
transform.GetChild(0).GetComponent<SpriteRenderer>().renderer.sortingOrder = -98;
Destroy(gameObject,5f);
}
// if (Time.time - timer > 10f && stopped)
// {
// Destroy(gameObject);
// }
}
void OnCollisionEnter(Collision col){
if ((col.gameObject.tag == "Wall" || col.gameObject.tag == "Player") && !stopped)
{
if (col.gameObject.tag == "Player") {
player.GetComponent<playerScript>().messiness += 33f;
}
die ();
}
}
void OnTriggerEnter(Collider col){
if(col.tag == "Shield")
{
if(!reflected)
{
Debug.Log("REFLECTED!");
target = new Vector3(target.x * -1, target.y * -1, target.z);
//Vector3 normal = new Vector3(player.transform.position.x - transform.position.x, player.transform.position.y - transform.position.y, 0);
//target = Vector3.Reflect(normal, target);
if (transform.position.x - player.transform.position.x > 0)
graphic.transform.localScale = new Vector3(Mathf.Abs(graphic.transform.localScale.x) * -1, graphic.transform.localScale.y, graphic.transform.localScale.z);
else
graphic.transform.localScale = new Vector3(Mathf.Abs(graphic.transform.localScale.x) * 1, graphic.transform.localScale.y, graphic.transform.localScale.z);
if (transform.position.y - player.transform.position.y <= 0)
pieFacing = false;
//
else if (transform.position.y - player.transform.position.y > 0)
pieFacing = true;
reflected = true;
}
}
}
void die()
{
//timer = Time.deltaTime;
stopped = true;
target = transform.position;
GetComponent<SphereCollider>().isTrigger = true;
//animator.SetTrigger("Die");
}
}