updated shoot mechanics

This commit is contained in:
2023-04-03 19:23:20 -04:00
parent 174e912d1f
commit 260ca88656
9 changed files with 1326 additions and 130 deletions

View File

@ -0,0 +1,30 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class BulletComponent : MonoBehaviour
{
[SerializeField]
private float duration = 5f;
private float existed = 0f;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
}
private void FixedUpdate()
{
if(existed >= duration)
{
Destroy(this.gameObject);
}
existed += Time.fixedDeltaTime;
}
}

View File

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

View File

@ -12,6 +12,16 @@ public class PistolComponent : MonoBehaviour
GameObject targetObject;
[SerializeField]
GameObject targetObjectPrefab;
[SerializeField]
private GameObject projectilePrefab;
[SerializeField]
private Transform bulletSpawnPoint;
[SerializeField]
private float firePower = 20f;
[SerializeField]
private float maxProjectileDuration = 5f;
//private Dictionary<int,float> projectiles = new Dictionary<int, float>();
// Start is called before the first frame update
void Start()
@ -37,9 +47,20 @@ public class PistolComponent : MonoBehaviour
targetObject.gameObject.transform.position = hit.point;
}
}
}
public void Fire()
{
GameObject projectile = Instantiate(projectilePrefab, this.bulletSpawnPoint);
projectile.transform.localPosition = Vector3.zero;
projectile.transform.localEulerAngles = Vector3.zero;
projectile.transform.localScale = Vector3.one;
Rigidbody pRigid = projectile.GetComponent<Rigidbody>();
pRigid.AddForce(pRigid.transform.up*this.firePower, ForceMode.Impulse);
projectile.transform.parent = null;
}
public void Enable()