Esempio n. 1
0
    void Start()
    {
        if (Instance == null)
        {
            Instance = this;
        }
        else
        {
            Destroy(this.gameObject);
            return;
        }

        rays       = new List <RayPlus>();
        removeRays = new List <RayPlus>();

        Client.AddCommand(PacketType.Shoot, ReceiveShoot);
        Client.AddCommand(PacketType.ShootServer, ReceiveShootServer);
    }
Esempio n. 2
0
    public void Shoot(bool activateCallbacks = false)
    {
        //rotate muzzle transform
        float r = gun.values.Range;

        muzzle.transform.localRotation = Quaternion.Euler(UnityEngine.Random.Range(-r, r), 0, UnityEngine.Random.Range(-r, r));
        //instanziate ray
        Ray ray = new Ray(muzzle.transform.position, muzzle.transform.forward);

        //method for start shooting
        float distance = shootingType == ShootingType.Single ? gun.values.MaxDistance : gun.values.Speed * Time.deltaTime;

        //if (Application.isEditor)
        //  Debug.DrawRay(ray.origin, ray.direction * distance, Color.red, 0.5f);

        //if it shot someone
        if (Physics.Raycast(ray, out raycastHit, distance))
        {
            //this method went call when
            if (activateCallbacks)
            {
                GameNetworkObject obj = raycastHit.collider.gameObject.GetComponent <GameNetworkObject>();
                if (obj != null)
                {
                    SendHitToHost(obj.NetworkId);
                }
            }
        }
        else if (shootingType == ShootingType.Consecutive) // else add the ray in a list
        {
            ShootsMgr.AddRay(new RayPlus(ray.origin + ray.direction * distance, ray.direction, distance, gun.values.Damage, gun.values.Speed, gun.values.MaxDistance, activateCallbacks));
        }
        //set rotation on identity
        muzzle.transform.localRotation = Quaternion.identity;

        gun.Shoot();
    }