-
Notifications
You must be signed in to change notification settings - Fork 0
/
SraCookies.cs
81 lines (67 loc) · 2.02 KB
/
SraCookies.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
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class SraCookies : MonoBehaviour
{
public GameObject GameController;
public int vida = 15;
public float speed;
private Rigidbody2D rb;
private Vector2 jumpForce = new Vector2(0, 350);
//tiro
public float reloadTime = .2f;
public ObjPool objPool;
private float timeForNextShot;
public GameObject especial;
public int chamaEspecial;
//Estado do Player
public string playerArma = "Pistola";
void Start()
{
rb = GetComponent<Rigidbody2D>();
}
void Update()
{
//Tiro
Vector2 position = new Vector2(transform.position.x - transform.localScale.x/2, transform.position.y + 0.5f);
if (Time.time >= timeForNextShot && GameController.GetComponent<Movimento>().atirar)
{
if (playerArma == "Pistola") {
GameObject bullet = objPool.Pistola ();
bullet.SetActive (true);
bullet.transform.position = position;
timeForNextShot = Time.time + reloadTime;
}
else if (playerArma == "Shotgun") {
GameObject bullet = objPool.Shotgun ();
bullet.SetActive (true);
bullet.transform.position = position;
timeForNextShot = Time.time + reloadTime;
}
}
if (chamaEspecial > 20) {
especial.gameObject.SetActive(true);
}
}
public void Cima()
{
rb.velocity = Vector2.zero;
rb.AddForce(jumpForce);
}
public void Esquerda()
{
transform.Translate(Vector2.left * speed * Time.deltaTime);
transform.localScale = new Vector3(1.5f, 2.8f, 1);
}
public void Direita()
{
transform.Translate(Vector2.right * speed * Time.deltaTime);
transform.localScale = new Vector3(-1.5f, 2.8f, 1);
}
void OnCollisionEnter2D(Collision2D hit)
{
if (hit.transform.CompareTag("Chao")) {
GameController.GetComponent<Movimento>().estadoPlayer = "Chao";
}
}
}