RayCast Entfernt und schießen verbessert
This commit is contained in:
@@ -7,23 +7,13 @@ using UnityEngine;
|
||||
public class BulletScript : MonoBehaviour
|
||||
{
|
||||
public DataBullet dataBullet;
|
||||
|
||||
private float damage;
|
||||
private float speed;
|
||||
private int ammo;
|
||||
|
||||
public GameObject particalClash;
|
||||
|
||||
public float lifetime = 3f;
|
||||
private Rigidbody rb;
|
||||
|
||||
private Vector3 direction;
|
||||
|
||||
private float time = 0f;
|
||||
|
||||
private Ray ray;
|
||||
private RaycastHit hit;
|
||||
|
||||
/// <summary>
|
||||
/// Sobald life Time vorbei ist Destroy die Bullet.
|
||||
/// </summary>
|
||||
@@ -33,11 +23,6 @@ public class BulletScript : MonoBehaviour
|
||||
GameObject.Destroy(this.gameObject);
|
||||
}
|
||||
}
|
||||
private void CheckForColliders(){
|
||||
if(Physics.Raycast(ray, out hit)){ //wenn true wird durch out in variable hit ein RayCastHit gespeichert
|
||||
direction = hit.point - transform.position;//Richtung in die, die Kugel fliegt
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// clashPartical spawned clashPartical am EinschlagPunkt der Kugel.
|
||||
/// </summary>
|
||||
@@ -69,18 +54,13 @@ public class BulletScript : MonoBehaviour
|
||||
rb = this.GetComponent<Rigidbody>();
|
||||
|
||||
Physics.IgnoreCollision(GetComponent<Collider>(),GameObject.Find("Player").GetComponent<Collider>());
|
||||
|
||||
|
||||
|
||||
ray = Camera.main.ViewportPointToRay(new Vector3(0.5f,0.5f,0f));
|
||||
CheckForColliders();
|
||||
}
|
||||
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
rb.velocity = direction.normalized * speed;
|
||||
rb.velocity = transform.forward * speed;
|
||||
die(lifetime);
|
||||
time += Time.deltaTime;
|
||||
}
|
||||
|
@@ -34,7 +34,7 @@ public class WeaponScript : MonoBehaviour
|
||||
if(Input.GetKeyDown(KeyCode.Mouse0)){
|
||||
muzzle.gameObject.SetActive(true);
|
||||
//muzzle.Play();
|
||||
Instantiate(bullet,spawnpoint.transform.position,transform.rotation);
|
||||
Instantiate(bullet,spawnpoint.transform.position,spawnpoint.transform.rotation);
|
||||
ammo--;
|
||||
}
|
||||
}else{
|
||||
@@ -46,7 +46,8 @@ public class WeaponScript : MonoBehaviour
|
||||
void Start()
|
||||
{
|
||||
ammo = dataBullet.ammo;
|
||||
muzzle = spawnpoint.GetComponentInChildren<ParticleSystem>();
|
||||
muzzle = GetComponentInChildren<ParticleSystem>();
|
||||
spawnpoint = GameObject.Find("Player/PlayerView/BulletSpawnpoint");
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
|
Reference in New Issue
Block a user