Files
GMTKGameJam2020/Assets/Scripts/BulletScript.cs
T

54 lines
1.1 KiB
C#
Raw Normal View History

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class BulletScript : MonoBehaviour
{
2020-07-11 10:51:01 -04:00
2020-07-12 01:07:52 -04:00
public AudioClip[] hit;
2020-08-10 23:36:52 -04:00
public Sprite secret;
2020-07-11 10:51:01 -04:00
private float speed;
private Rigidbody2D rb;
private ShakeScript shake;
2020-07-12 01:07:52 -04:00
private AudioSource audioSource;
void Start()
{
2020-07-12 01:07:52 -04:00
audioSource = GetComponent<AudioSource>();
rb = GetComponent<Rigidbody2D>();
2020-07-11 10:51:01 -04:00
speed = Random.Range(3.0f, 8.0f);
shake = GameObject.Find("Shake Manager").GetComponent<ShakeScript>();
shake.CamShake();
2020-08-10 23:36:52 -04:00
if(Random.Range(0, 100) == 0) this.GetComponent<SpriteRenderer>().sprite = secret;
}
void FixedUpdate()
{
rb.velocity = transform.up * speed;
}
void OnCollisionEnter2D(Collision2D other)
{
if(other.gameObject.tag != "Player" && other.gameObject.tag != "Bullet")
{
2020-07-12 01:07:52 -04:00
AudioSource.PlayClipAtPoint(
hit[Random.Range(0,hit.Length)], new Vector3(0, 0, 0));
Destroy(gameObject);
}
}
void OnBecameInvisible()
{
Destroy(gameObject);
}
}