RayCast von Maincamera aus, damit die Kugel die man Abfeuert auch im Crosshair landet
This commit is contained in:
@@ -4,30 +4,38 @@ using UnityEngine;
|
||||
|
||||
public class BulletMoving : MonoBehaviour
|
||||
{
|
||||
public GameObject child;
|
||||
|
||||
public DataBullet dataBullet;
|
||||
|
||||
public float lifetime = 3f;
|
||||
[SerializeField]
|
||||
private Rigidbody rb;
|
||||
|
||||
private Vector3 direction = new Vector3(0f,0f,0f);
|
||||
private Vector3 direction;
|
||||
|
||||
private float time = 0f;
|
||||
|
||||
private Ray ray;
|
||||
private RaycastHit hit;
|
||||
|
||||
private void die(float lifetime){
|
||||
if(time > lifetime){
|
||||
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
|
||||
}
|
||||
}
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
rb = this.GetComponent<Rigidbody>();
|
||||
direction = child.transform.position - transform.position;
|
||||
|
||||
|
||||
ray = Camera.main.ViewportPointToRay(new Vector3(0.5f,0.5f,0f));
|
||||
CheckForColliders();
|
||||
}
|
||||
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
|
@@ -13,5 +13,5 @@ MonoBehaviour:
|
||||
m_Name: DataBullet
|
||||
m_EditorClassIdentifier:
|
||||
damage: 10
|
||||
speed: 20
|
||||
speed: 5
|
||||
ammo: 4
|
||||
|
@@ -7,7 +7,6 @@ public class WeaponScript : MonoBehaviour
|
||||
|
||||
public GameObject spawnpoint;
|
||||
public GameObject bullet;
|
||||
|
||||
|
||||
private void shoot(){
|
||||
if(Input.GetKeyDown(KeyCode.Mouse0)){
|
||||
|
Reference in New Issue
Block a user