GlobalGameJame/Assets/Scripts/AmmoManager.cs

47 lines
1.5 KiB
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class AmmoManager : MonoBehaviour
{
public enum AmmoType { None, Shuriken, Bullet };
public AmmoType ammoType = AmmoType.None;
public Rigidbody rigidBody;
public WeaponManager weaponManager;
// Start is called before the first frame update
void Start()
{
if (ammoType == AmmoType.Shuriken)
{
rigidBody.AddForce(weaponManager.transform.forward * weaponManager.weaponRange, ForceMode.VelocityChange);
rigidBody.AddTorque(weaponManager.transform.right * 5, ForceMode.Force);
Destroy(this.gameObject, 5f);
}
}
// Update is called once per frame
void Update()
{
}
public void OnCollisionEnter(Collision collision)
{
if (ammoType == AmmoType.Shuriken) {
if (collision.transform.tag != "Player") {
rigidBody.isKinematic = true;
rigidBody.velocity = Vector3.zero;
rigidBody.useGravity = false;
rigidBody.constraints = RigidbodyConstraints.FreezeAll;
GetComponent<TrailRenderer>().enabled = false;
}
if (collision.transform.tag == "Enemy")
{
transform.root.parent = collision.transform.root.transform;
collision.transform.GetComponent<EnemyManager>().Damage(weaponManager.damage);
}
}
}
}