add catana, shurikens and repair weapon changin and meele weapon animation

This commit is contained in:
haitem
2021-09-21 23:09:33 +02:00
parent 2ecd9d20ac
commit 6741aa8b4d
53 changed files with 15052 additions and 1703 deletions

View File

@@ -0,0 +1,46 @@
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);
}
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: dfc054dea21bd894997c749bfb9c315a
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -175,7 +175,7 @@ public class EnemyManager : MonoBehaviour
void Attack()
{
RaycastHit hit;
if (Physics.Raycast(transform.position + new Vector3(0,0.5f,0),transform.forward,out hit,1.5f) && attackTime <= Time.time)
if (Physics.Raycast(transform.position + new Vector3(0,0.5f,0),transform.forward,out hit,1f) && attackTime <= Time.time)
{
if (hit.transform.CompareTag("Player"))
{
@@ -201,15 +201,42 @@ public class EnemyManager : MonoBehaviour
Damage();
}
}
WeaponManager weaponManager = null;
bool localHit = false;
void OnTriggerEnter(Collider collider)
{
if (collider.transform.CompareTag("Meele"))
{
WeaponManager weaponManager = collider.transform.GetComponent<WeaponManager>();
if (weaponManager != null && weaponManager.hit) {
weaponManager = collider.transform.GetComponent<WeaponManager>();
if (weaponManager == null)
{
weaponManager = collider.transform.parent.GetComponent<WeaponManager>();
}
localHit = weaponManager.hit;
if (weaponManager != null && localHit) {
Damage();
weaponManager.hit = false;
localHit = false;
}
}
}
void OnTriggerStay(Collider collider)
{
if (collider.transform.CompareTag("Meele"))
{
bool offOn = false;
if (weaponManager.hit == false) {
offOn = true;
}
if (weaponManager.hit == true && offOn)
{
localHit = weaponManager.hit;
offOn = false;
}
if (weaponManager != null && localHit)
{
Damage();
localHit = false;
}
}
}

View File

@@ -39,6 +39,6 @@ public class GuiManager : MonoBehaviour
public void setWave(int wave)
{
waves.text = "Wave: " + wave;
waves.text = wave.ToString();
}
}

View File

@@ -26,8 +26,8 @@ public class PlayerManager : MonoBehaviour
public Sprite handImage;
public GuiManager guiManager;
public int selectedWeapon = 0;
private float selectRate = 1;
private float selectTime = 1;
private float selectRate = 0.1f;
private float selectTime = 0.1f;
public AudioSource audio;
public AudioClip lose;
private float nextMapeTime = 3;

View File

@@ -4,7 +4,7 @@ using UnityEngine;
public class WeaponManager : MonoBehaviour
{
public enum WeaponType { None, Shoot, Meele };
public enum WeaponType { None, Shoot, Meele, Throw };
public WeaponType weaponType = WeaponType.None;
public float weaponRange = 1;
public GameObject spawnShoot;
@@ -50,17 +50,44 @@ public class WeaponManager : MonoBehaviour
fireTime = fireRate + Time.time;
}
}
else if (weaponType == WeaponType.Throw)
{
if (particleShoot != null && player.ammo > (ammoCost - 1))
{
GameObject shoot = Instantiate(particleShoot, spawnShoot.transform.position, spawnShoot.transform.rotation);
if (shootSound.Count > 0)
{
int rand = Random.Range(0, shootSound.Count);
audioSource.PlayOneShot(shootSound[rand]);
}
shoot.GetComponent<AmmoManager>().weaponManager = this;
player.ammo -= ammoCost;
fireTime = fireRate + Time.time;
}
}
else if (weaponType == WeaponType.Meele)
{
hit = true;
animator.ResetTrigger("Hit");
animator.SetTrigger("Hit");
fireTime = fireRate + Time.time;
}
}
if (fireTime <= Time.time)
{
if (animator != null) {
animator.ResetTrigger("Hit");
}
hit = false;
}
}
public void Hit_Enemy_Start ()
{
hit = true;
}
public void Hit_Enemy_End ()
{
hit = false;
}
}