Example #1
0
 private void beginShoot(Vector3 hitPos)
 {
     Destroy(Instance);
     Instance    = Instantiate(LaserPrefabs, hitPos, Quaternion.identity);
     LaserScript = Instance.GetComponent <EGA_Laser>();
     LaserScript.ShootLaser(hitPos);
 }
Example #2
0
 private void beginShoot()
 {
     Destroy(Instance);
     Instance    = Instantiate(LaserPrefabs, transform.position, transform.rotation);
     LaserScript = Instance.GetComponent <EGA_Laser>();
     LaserScript.ShootLaser();
 }
Example #3
0
    void Update()
    {
        //Enable lazer
        if (Input.GetMouseButtonDown(0))
        {
            Destroy(Instance);
            Instance = Instantiate(Prefabs[Prefab], FirePoint.transform.position, FirePoint.transform.rotation);
            Instance.transform.parent = transform;
            LaserScript = Instance.GetComponent <EGA_Laser>();
        }

        //Disable lazer prefab
        if (Input.GetMouseButtonUp(0))
        {
            LaserScript.DisablePrepare();
            Destroy(Instance, 1);
        }

        //To change lazers
        if ((Input.GetKey(KeyCode.A) || Input.GetAxis("Horizontal") < 0) && buttonSaver >= 0.4f)// left button
        {
            buttonSaver = 0f;
            Counter(-1);
        }
        if ((Input.GetKey(KeyCode.D) || Input.GetAxis("Horizontal") > 0) && buttonSaver >= 0.4f)// right button
        {
            buttonSaver = 0f;
            Counter(+1);
        }
        buttonSaver += Time.deltaTime;


        //Current fire point
        if (Cam != null)
        {
            RaycastHit hit; //DELATE THIS IF YOU WANT TO USE LASERS IN 2D
            var        mousePos = Input.mousePosition;
            RayMouse = Cam.ScreenPointToRay(mousePos);
            //ADD THIS IF YOU WANT TO USE LASERS IN 2D: RaycastHit2D hit = Physics2D.Raycast(RayMouse.origin, RayMouse.direction, MaxLength);
            if (Physics.Raycast(RayMouse.origin, RayMouse.direction, out hit, MaxLength)) //CHANGE THIS IF YOU WANT TO USE LASERRS IN 2D: if (hit.collider != null)
            {
                RotateToMouseDirection(gameObject, hit.point);
                //LaserEndPoint = hit.point;
            }
            else
            {
                var pos = RayMouse.GetPoint(MaxLength);
                RotateToMouseDirection(gameObject, pos);
                //LaserEndPoint = pos;
            }
        }
        else
        {
            Debug.Log("No camera");
        }
    }
 private void beginShoot()
 {
     Destroy(Instance);
     //ps.SetActive(true);
     Instance = Instantiate(Prefabs[Prefab], FirePoint.transform.position, FirePoint.transform.rotation);
     //ps.transform.position = FirePoint.transform.position;
     //ps.transform.rotation = FirePoint.transform.rotation;
     //ps.transform.parent = transform;
     //Instance.transform.parent = transform;
     LaserScript = Instance.GetComponent <EGA_Laser>();
     //LaserScript.UpdateSaver = true;
     LaserScript.ShootLaser(new Vector3(0, 4, 8));
 }