updated shoot mechanics
This commit is contained in:
30
Assets/Scripts/Pistol/BulletComponent.cs
Normal file
30
Assets/Scripts/Pistol/BulletComponent.cs
Normal 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;
|
||||
|
||||
}
|
||||
}
|
11
Assets/Scripts/Pistol/BulletComponent.cs.meta
Normal file
11
Assets/Scripts/Pistol/BulletComponent.cs.meta
Normal file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9ea1ee4df8019a143b013f8837aa48d8
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -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()
|
||||
|
Reference in New Issue
Block a user