- Home /
Shooting style like enter the dungeon
Hello, I'm trying to make a game like "enter the dungeon" but I do not know why the bullets go badly shot :v
These are my scripts:
 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class Bullet : MonoBehaviour {
 
     public float MoveSpeed;
     public float LifeTime;
     public float Distance;
     public LayerMask whatIsSolid;
 
     void Start ()
     {
         Invoke ("DestroyBullet", LifeTime);
     }
     
     void Update ()
     {
         RaycastHit2D hitInfo = Physics2D.Raycast (transform.position, transform.up, Distance, whatIsSolid);
 
         if (hitInfo.collider != null)
         {
             if (hitInfo.collider.tag == "Enemy")
             {
                 Debug.Log ("Enemy");
             }
 
             DestroyBullet ();
         }
 
         transform.Translate (transform.up * MoveSpeed * Time.deltaTime);
     }
 
     public void DestroyBullet ()
     {
         Destroy (gameObject);
     }
 }
 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class BasicGun : MonoBehaviour {
 
     public float offset;
 
     public GameObject Bullet;
     public Transform ShootPoint;
 
     private float TimeBtwShoots;
     public float StartTimeBtwShoots;
 
     void Start ()
     {
         
     }
     
     void Update ()
     {
         Vector3 difference = Camera.main.ScreenToWorldPoint (Input.mousePosition) - transform.position;
         float rotZ = Mathf.Atan2 (difference.y, difference.x) * Mathf.Rad2Deg;
         transform.rotation = Quaternion.Euler (0f, 0f, rotZ + offset);
 
         if (TimeBtwShoots <= 0)
         {
             if (Input.GetMouseButtonDown (0))
             {
                 Instantiate (Bullet, ShootPoint.position, transform.rotation);
                 TimeBtwShoots = StartTimeBtwShoots;
             }
         }
         else
         {
             TimeBtwShoots -= Time.deltaTime;
         }
     }
 }
               Comment
              
 
               
              Your answer
 
 
             Follow this Question
Related Questions
Random Raycast inside crosshairs 1 Answer
How should I handle masses of bullets? 1 Answer
Raycasr in my fps? 1 Answer
Transform.translate bullets problem 0 Answers
 koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                