init
This commit is contained in:
commit
862afc9b7a
478 changed files with 197737 additions and 0 deletions
43
Assets/Scripts/BulletScript.cs
Normal file
43
Assets/Scripts/BulletScript.cs
Normal file
|
@ -0,0 +1,43 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class BulletScript : MonoBehaviour
|
||||
{
|
||||
public float damage;
|
||||
public GameObject bulletImpact;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
AudioManager.instance.Play("Shoot");
|
||||
}
|
||||
|
||||
void Update() {
|
||||
Vector2 vel = gameObject.GetComponent<Rigidbody2D>().velocity;
|
||||
gameObject.transform.rotation = Quaternion.Euler(new Vector3(0,0,Mathf.Rad2Deg * Mathf.Atan2(vel.y,vel.x)));
|
||||
}
|
||||
|
||||
private void OnCollisionEnter2D(Collision2D collision) {
|
||||
AudioManager.instance.Play("ShootCollide");
|
||||
CameraShake.instance.Shake(.1f, .1f);
|
||||
Instantiate(bulletImpact, transform.position, Quaternion.identity);
|
||||
Button button = collision.transform.GetComponent<Button>();
|
||||
if (!button)
|
||||
Object.Destroy(gameObject);
|
||||
else if(!button.bulletProof)
|
||||
{
|
||||
button.Press();
|
||||
Destroy(gameObject);
|
||||
}
|
||||
hasHP hp;
|
||||
if (collision.gameObject.TryGetComponent<hasHP>(out hp)) {
|
||||
Debug.Log("Damaging");
|
||||
hp.damage(damage);
|
||||
}
|
||||
Debug.Log(collision.otherCollider.gameObject.name);
|
||||
if (collision.otherCollider.gameObject.name.Equals("Player")) {
|
||||
collision.otherCollider.gameObject.GetComponent<PlayerStats>().Die();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue