-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPlayerController.cs
76 lines (58 loc) · 2.07 KB
/
PlayerController.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
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerController : MonoBehaviour
{
[System.Serializable]
public class Settings
{
[Header("Movement Settings")]
public float movementSpeed;
[Header("Bullet Settings")]
public float bulletSpeed;
public GameObject LipsSpawn;
public GameObject[] lipsPrefabs;
public float bulletDieTime;
public float fireRate;
}
public Settings settings;
private float totalTime;
public float score;
public float unChangingScore;
public bool isDead = false;
void Update()
{
float xMove = Input.GetAxisRaw("Horizontal");
float yMove = Input.GetAxisRaw("Vertical");
Vector3 moveVector = new Vector3(xMove, yMove, 0.0f);
if (Input.GetKeyDown(KeyCode.LeftArrow) && totalTime < Time.time)
{
Fire(-1);
totalTime = Time.time + settings.fireRate;
}
if (Input.GetKeyDown(KeyCode.RightArrow) && totalTime < Time.time)
{
Fire(1);
totalTime = Time.time + settings.fireRate;
}
moveVector *= settings.movementSpeed;
this.transform.position += moveVector;
}
public void Fire(int direction)
{
int randomInt = Random.Range(0, 2);
GameObject bullet = settings.lipsPrefabs[randomInt];
Vector2 bulletForce = new Vector2(settings.bulletSpeed, 0.0f);
GameObject bulletInstance = Instantiate(bullet, settings.LipsSpawn.transform.position, Quaternion.identity);
bulletInstance.GetComponent<Rigidbody2D>().AddForce(bulletForce * direction);
Destroy(bulletInstance, settings.bulletDieTime);
}
void OnCollisionEnter2D(Collision2D other)
{
if(other.collider.tag == "Enemy" || other.collider.tag == "Boss Bullet")
{
isDead = true;
transform.FindChild("catullusFace").gameObject.SetActive(false);
}
}
}