Repository navigation
Expand file tree
/
Copy pathTarget.cs
More file actions
71 lines (59 loc) · 1.76 KB
/
Copy pathTarget.cs
File metadata and controls
71 lines (59 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
67
68
69
70
71
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Target : MonoBehaviour
{
private Rigidbody targetRb;
private GameManager gameManager;
public ParticleSystem explosionParticle;
private float minSpeed = 12;
private float maxSpeed = 16;
private float torqueRange = 10;
private float xRange = 4;
private float ySpawnPos = -6;
[SerializeField] private int pointValue;
// Start is called before the first frame update
void Start()
{
gameManager = GameObject.Find("GameManager").GetComponent<GameManager>();
targetRb = GetComponent<Rigidbody>();
transform.position = RandomSpawnPos();
targetRb.AddForce(RandomForce(), ForceMode.Impulse);
targetRb.AddTorque(
RandomTorque(),
RandomTorque(),
RandomTorque(),
ForceMode.Impulse
);
}
// Update is called once per frame
void Update()
{
}
private void OnMouseDown()
{
Instantiate(explosionParticle, transform.position, explosionParticle.transform.rotation);
Destroy(gameObject);
gameManager.UpdateScore(pointValue);
}
private void OnTriggerEnter(Collider other)
{
if (!gameObject.CompareTag("Bad"))
{
gameManager.GameOver();
}
Destroy(gameObject);
}
private Vector3 RandomForce()
{
return Vector3.up * Random.Range(minSpeed, maxSpeed);
}
private Vector3 RandomSpawnPos()
{
return new Vector3(Random.Range(-xRange, xRange), ySpawnPos);
}
private float RandomTorque()
{
return Random.Range(-torqueRange, torqueRange);
}
}