Inheritance: MonoBehaviour
	public override void Impulse(ImpulseType type)
	{
		if(!m_Weapon) {
			m_Weapon = GetComponent<Shootable>();
		}

		if(m_Weapon) {
			Item weapon_item = GetComponent<Item>();
			FirstPersonMovementController movement_controller = (weapon_item && weapon_item.Owner ? weapon_item.Owner.GetComponent<FirstPersonMovementController>() : null);
			Transform camera_anchor = (movement_controller ? movement_controller.CameraAnchor : null);

			switch(type) {
				case ImpulseType.ATTACK:
					m_Weapon.Fire(camera_anchor);
					break;

				case ImpulseType.REFRESH:
					m_Weapon.Reload();
					break;

				default:
					base.Impulse(type);
					break;
			}
		}
	}
    void Update()
    {
        if (Input.GetButtonDown("Fire1") && Time.time > nextFire)
        {
            nextFire = Time.time + fireRate;

            StartCoroutine(ShotEfect());
            Vector3    rayOrigin = fpsCam.ViewportToWorldPoint(new Vector3(.5f, .5f, 0));
            RaycastHit hit;
            laserline.SetPosition(0, gunEnd.position);

            if (Physics.Raycast(rayOrigin, fpsCam.transform.forward, out hit, weaponRange))
            {
                laserline.SetPosition(1, hit.point);
                Shootable health = hit.collider.GetComponent <Shootable>();

                if (health != null)
                {
                    health.Damage(gunDamage);
                }

                if (hit.rigidbody != null)
                {
                    hit.rigidbody.AddForce(-hit.normal * hitForce);
                }
            }
            else
            {
                laserline.SetPosition(1, rayOrigin + (fpsCam.transform.forward * weaponRange));
            }
        }
    }
示例#3
0
文件: Bullet.cs 项目: rje/rubbertron
    bool IsNotShooter(Shootable toCheck)
    {
        var firedByPlayer = m_firedBy == Gunner.Player;
        var targetIsPlayer = toCheck.CompareTag("Player");

        return firedByPlayer != targetIsPlayer;
    }
    void Start()
    {
        rmData    = GetComponent <RadarManager>();
        rocketHUD = GameObject.Find("fake weapon hud").GetComponent <Image>();;
        rocketHUD.gameObject.SetActive(true);
        SpeedReadout    = GameObject.Find("Speed");
        throttleReadout = GameObject.Find("Throttle");

        if (optionalDangerHeightReadout)
        {
            dangerBaseText = optionalDangerHeightReadout.text;
        }

        mFlash = GetComponent <MuzzleFlash>();
        mFlash.Reset();
        StartCoroutine(rocketSalvoRelease());
        shootableScript    = GetComponent <Shootable>();
        wasHealth          = startHealth = shootableScript.healthLimit;
        UI_ThrottleReadout = throttleReadout.GetComponent <UI_Speed> ();
        UI_SpeedReadout    = SpeedReadout.GetComponent <UI_Speed> ();

        hardpointRef = missionTarget.GetComponentInChildren <HardPointCounter>();

        hardpointMax = hardpointRef.hardpointCount;
    }
    //void Update()

    public void Fire()
    {
        //if ((Input.GetMouseButton(0) != false || Input.GetAxisRaw("Right_Trigger") != 0) && Time.time > nextFire) //Fire1 = ctrl, jump = space
        if (Time.time > nextFire) //Fire1 = ctrl, jump = space
        {
            //GetMouseButtonDown is once per click, GetMouseButton checks every frame
            nextFire = Time.time + fireRate;
            StartCoroutine(ShotEffect());

            //Vector3 rayOrigin = fpsCam.ViewportToWorldPoint(new Vector3(0.5f, 0.5f, 0)); //gets exact center of fps cam
            //Vector3 rayOrigin = transform.forward;
            RaycastHit hit;

            laserLine.SetPosition(0, gunEnd.position);
            if (Physics.Raycast(transform.position, transform.forward, out hit, weaponRange))
            {
                laserLine.SetPosition(1, hit.point);
                Shootable health = hit.collider.GetComponent <Shootable>();
                if (health != null)
                {
                    health.Damage(gunDamage);
                }
                if (hit.rigidbody != null)
                {
                    hit.rigidbody.AddForce(-hit.normal * hitForce);
                }
            }
            else
            {
                laserLine.SetPosition(1, transform.position + (transform.forward * weaponRange));
            }
        }
    }
    public override void Impulse(ImpulseType type)
    {
        if (!m_Weapon)
        {
            m_Weapon = GetComponent <Shootable>();
        }

        if (m_Weapon)
        {
            Item weapon_item = GetComponent <Item>();
            FirstPersonMovementController movement_controller = (weapon_item && weapon_item.Owner ? weapon_item.Owner.GetComponent <FirstPersonMovementController>() : null);
            Transform camera_anchor = (movement_controller ? movement_controller.CameraAnchor : null);

            switch (type)
            {
            case ImpulseType.ATTACK:
                m_Weapon.Fire(camera_anchor);
                break;

            case ImpulseType.REFRESH:
                m_Weapon.Reload();
                break;

            default:
                base.Impulse(type);
                break;
            }
        }
    }
示例#7
0
    // Start is called before the first frame update
    void Start()
    {
        RaycastHit hit;
        Ray        ray = new Ray();

        ray.origin    = transform.position;
        ray.direction = transform.forward;

        if (Physics.Raycast(ray, out hit, 10000, mask.value, QueryTriggerInteraction.Ignore))
        {
            Debug.DrawRay(ray.origin, ray.direction * 10000);
            GameObject     go  = GameObject.Instantiate(puff, hit.point, Quaternion.Inverse(transform.rotation));
            ParticleSystem ps  = go.GetComponent <ParticleSystem>();
            Suppression    sup = go.GetComponent <Suppression> ();
            sup.origin = transform.position;
            if (hit.collider.attachedRigidbody)
            {
                Shootable s = hit.collider.attachedRigidbody.gameObject.GetComponent <Shootable>();
                if (s != null)
                {
                    s.getShot(d);
                    ParticleSystem.ColorOverLifetimeModule coltm = ps.colorOverLifetime;
                    coltm.color = Color.red;
                }
            }
        }
    }
示例#8
0
    void DrawShoot(int index, int dmg)
    {
        StartCoroutine(ShotEffect(index));
        Vector3 realDirection  = fpsCam.transform.forward;
        Vector3 shootDirection = realDirection + new Vector3(
            Random.Range(-0.05f * index, 0.05f * index),
            Random.Range(-0.05f * index, 0.05f * index),
            Random.Range(-0.05f * index, 0.05f * index)
            );
        Vector3    rayOrigin = fpsCam.ViewportToWorldPoint(new Vector3(.5f, .5f, 0));
        RaycastHit hit;

        linesRenderer[index].SetPosition(0, gunEnd.position);
        if (Physics.Raycast(rayOrigin, shootDirection, out hit, weaponRange))
        {
            linesRenderer[index].SetPosition(1, hit.point);
            Shootable shootableComponent = hit.collider.GetComponent <Shootable>();
            if (shootableComponent != null)
            {
                shootableComponent.Damage(dmg);
            }

            BossBehavior boosBehavior = hit.collider.GetComponent <BossBehavior>();
            if (boosBehavior != null)
            {
                boosBehavior.ReceiveDamage(dmg);
            }
        }
        else
        {
            linesRenderer[index].SetPosition(1, rayOrigin + (shootDirection * weaponRange));
        }
    }
示例#9
0
文件: Raycast.cs 项目: ahmadcah/MyFPS
 void Update()
 {
     if (Input.GetMouseButtonDown(0) && nextFire > FireRate)
     {
         nextFire = 0;
         StartCoroutine(shotEffect());
         Vector3    rayOrigin = fpsCam.ViewportToWorldPoint(new Vector3(0.5f, 0.5f, 0));
         RaycastHit hit;
         if (Physics.Raycast(rayOrigin, fpsCam.transform.forward, out hit, weaponRange))
         {
             Shootable health = hit.collider.GetComponent <Shootable> ();
             laserLine.transform.LookAt(hit.point);
             var clone = Instantiate(laserEffect, hit.point, Quaternion.LookRotation(hit.normal));
             Destroy(clone.gameObject, 4);
             if (health != null)
             {
                 health.Damage(damage);
             }
             if (hit.rigidbody != null)
             {
                 hit.rigidbody.AddForce(-hit.normal * hitForce);
             }
         }
         else
         {
             laserLine.transform.LookAt(rayOrigin + (fpsCam.transform.forward * weaponRange));
         }
     }
     nextFire         += Time.deltaTime;
     laserEnergy.value = nextFire;
 }
示例#10
0
    IEnumerator targetScan()
    {
        while (true)
        {
            yield return(new WaitForSeconds(Random.Range(0.1f, 0.5f)));

            if (target == null)
            {
                Collider [] possibleTargets = Physics.OverlapSphere(transform.position + transform.forward * 1500.0f, 1495.0f);
                foreach (Collider consider in possibleTargets)
                {
                    Shootable shootMeScript = consider.GetComponent <Shootable>();
                    if (shootMeScript && shootMeScript.healthLimit > 0 && shootMeScript.canBeTarget)
                    {
                        RaycastHit rhInfo;
                        Vector3    toward    = consider.transform.position - transform.position;
                        int        layerMask = ~(1 << 12);
                        if (Physics.Raycast(transform.position + toward.normalized * 5.0f,
                                            toward,
                                            out rhInfo, 19999.0f, layerMask) &&
                            rhInfo.transform.gameObject == consider.gameObject)
                        {
                            target = consider.transform;
                        }
                    }
                }
            }
            if (target)
            {
                StopCoroutine(targetLooker);
                break;
            }
        }
    }
示例#11
0
 // Use this for initialization
 void Start () {
     shootable = GetComponent<Shootable>();
     LeanTween.scale(gameObject, new Vector3(1.5f, 1.5f, 1f), explosionTime).setOnComplete(()=>
     {
         Explosion(false);
     });
     //iTween.ScaleTo(gameObject, iTween.Hash("scale", new Vector3(1f, 1f, 1f), "time", explosionTime, "easetype", iTween.EaseType.linear,));
 }
示例#12
0
    void Update()
    {
        Shootable shootable = bullet.GetComponent <Shootable>();

        if (Input.GetKeyDown(KeyCode.Space) && energyReserve.ConsumeEnergy(shootable.energyCost))
        {
            GameObject bulletInstance = Instantiate(bullet, transform.position, transform.rotation);
        }
    }
示例#13
0
 // Use this for initialization
 void Start()
 {
     shootable = GetComponent <Shootable>();
     LeanTween.scale(gameObject, new Vector3(1.5f, 1.5f, 1f), explosionTime).setOnComplete(() =>
     {
         Explosion(false);
     });
     //iTween.ScaleTo(gameObject, iTween.Hash("scale", new Vector3(1f, 1f, 1f), "time", explosionTime, "easetype", iTween.EaseType.linear,));
 }
示例#14
0
    // --- Public/Internal Methods ------------------------------------------------------------------------------------

    public void OnHit(Shootable bullet, Collision collision)
    {
        _wallHitSound.Play();
        //if (!SettingsManager.BouncyBullets)
        //{
        //    bullet.Explode();
        //}
        //bullet.Reflect(collision);
    }
示例#15
0
 protected IEnumerator ShootingRoutine()
 {
     for (int i = 0; i < numBullets; ++i)
     {
         Shootable shootable = Instantiate(bulletPrefab);
         shootable.OnShot(transform);
         yield return(new WaitForSeconds(bulletFrequency));
     }
 }
示例#16
0
    private void Shoot(RaycastHit hit)
    {
        Shootable shootable = hit.transform.GetComponent <Shootable>();

        if (shootable != null)
        {
            Spawner.Instance.HitShootable(hit.transform.gameObject);
        }
    }
示例#17
0
    void Start()
    {
        _shootable = GetComponent <Shootable>();
        _shootable._onShot.AddListener(OnShot);

        _animator = GetComponent <Animator>();
        _isAlive  = true;
        ResetTimeToFire();
        _timeToFire += UnityEngine.Random.Range(0f, ShootTimeToFire);
    }
示例#18
0
    void Start()
    {
        //we know in this case the prefab is just 1 GameObject
        loadedAmmo  = ((GameObject)shootablePrefab).GetComponentsInChildren <Shootable> (true) [0];
        ammoStorage = AmmoStorage.Instance;         //singleton
        Transform baseAmmoTransform = loadedAmmo.GetComponentsInChildren <Transform> (true) [0];

        baseAmmoRotation = baseAmmoTransform.rotation;
        triggerPulled    = false;
        timeSinceShot    = 0F;
    }
示例#19
0
    // Start is called before the first frame update
    void Start()
    {
        vrGun = GameObject.FindGameObjectWithTag("Gun").GetComponent <VrGun>();

        try{
            //gun = GetComponent<ArduinoListener>();
            gun = GameObject.Find("BT_Object").GetComponent <BluetoothController>();
        }catch (System.Exception) {
            Debug.Log("BT_Object não foi encontrado");
        }
    }
示例#20
0
    private void OnCollisionEnter2D(Collision2D collision)
    {
        Debug.Log("Hit" + collision.collider.name);
        Shootable shootable = collision.collider.gameObject.GetComponent <Shootable>();

        if (shootable)
        {
            shootable.Damage(Damage);
        }
        gameObject.SetActive(false);
    }
 void OnCollisionEnter(Collision other)
 {
     if (other.gameObject.tag == "Enemy" || other.gameObject.tag == "Bullet") //|| other.gameObject.tag == "Shield")
     {
         Shootable health = other.gameObject.GetComponent <Shootable>();
         if (health != null)
         {
             health.Damage(gunDamage);
         }
     }
     Destroy(gameObject);
 }
示例#22
0
    protected virtual void FireRound(GameObject muzzle)
    {
        //get bullet from pool
        PooledObject bullet = ObjectPoolManager.Get(Projectile.gameObject);

        //get the actual bullet part from the bullet
        Shootable shootBase = bullet.gameObject.GetComponent <Shootable>();

        //actually shoot it
        shootBase.Fire(muzzle.transform.position, muzzle.transform.rotation, muzzle.transform.up, bullet);
        Source.Play();
    }
示例#23
0
    void Start()
    {
        if (shootable == null)
        {
            shootable = GetComponent <Shootable>();
        }

        if (transformToRotate == null)
        {
            transformToRotate = transform;
        }
    }
 // Use this for initialisation
 void OnCollisionEnter(Collision other)
 {
     if ((other.gameObject.tag == "Enemy" && repulsed) || other.gameObject.tag == "Player" || other.gameObject.tag == "Bullet") //|| other.gameObject.tag == "Shield")
     {
         Shootable health = other.gameObject.GetComponent <Shootable>();
         if (health != null)
         {
             health.Damage(gunDamage);
         }
         //Debug.Log("Id of victim: " + other.gameObject.name + ", health = " + other.gameObject.GetComponent<Shootable>().currentHealth);
     }
     Destroy(gameObject);
 }
示例#25
0
    private void OnTriggerEnter2D(Collider2D hitInfo)
    {
        Shootable shootable = hitInfo.GetComponent <Shootable>();

        if (shootable != null)
        {
            if (effect != null)
            {
                Instantiate(effect, transform.position, Quaternion.identity);
            }
            Destroy(gameObject);
        }
    }
示例#26
0
    void Update()
    {
        if (Input.GetButtonDown("Fire1") && Time.time > nextFire && gunAmmo > 0)
        {
            nextFire = Time.time + fireRate;

            StartCoroutine(ShotEffect());

            Vector3 rayOrigin = fpsCam.ViewportToWorldPoint(new Vector3(0.5f, 0.5f, 0.0f));

            RaycastHit hit;

            laserLine.SetPosition(0, gunEnd.position);

            if (Physics.Raycast(rayOrigin, fpsCam.transform.forward, out hit, weaponRange))
            {
                laserLine.SetPosition(1, hit.point);
                Shootable health = hit.collider.GetComponent <Shootable>();

                if (health != null)
                {
                    health.Damage(gunDamage);
                }

                if (hit.rigidbody != null)
                {
                    hit.rigidbody.AddForce(-hit.normal * hitForce);
                }
            }
            else
            {
                laserLine.SetPosition(1, rayOrigin + (fpsCam.transform.forward * weaponRange));
            }
        }
        if (Input.GetKeyDown(KeyCode.R) && ammo > 0)
        {
            if (ammo < 9)
            {
                gunAmmo = ammo;
                ammo    = 0;
                currentAmmo();
            }
            else
            {
                ammo    = gunAmmo + ammo - 9;
                gunAmmo = 9;
                currentAmmo();
            }
        }
    }
示例#27
0
    public void BulletScript()
    {
        RaycastHit hit;

        if (Physics.Raycast(transform.position, transform.forward * 100000, out hit))
        {
            Shootable ObjectThatWasShot = hit.collider.GetComponent <Shootable>();

            if (ObjectThatWasShot != null)
            {
                ObjectThatWasShot.GetShot();
            }
        }
    }
示例#28
0
 public void Shoot(Shootable Item)
 {
     // send an RPC to shoot a bullet on the local client and on all other clients
     // this is done because the local player has to hold the gun in a game object that is the child of the camera
     if (pickUpDestinationLocal.transform.GetChild(0).GetComponent <Gun>().Ammo > 0)
     {
         photonView.RPC("CreateBullet", RpcTarget.Others);
         photonView.RPC("CreateBulletLocal", PhotonNetwork.LocalPlayer);
     }
     else
     {
         pickUpDestinationLocal.transform.GetChild(0).GetComponent <Gun>().EmptyGunShot();
     }
 }
示例#29
0
    IEnumerator Fire(Ray ray)
    {
        if (m_firing || (m_hasFired && !m_isAutomatic) || m_reloading || !HasAmmo())
        {
            return(false);
        }
        m_firing   = true;
        m_hasFired = true;
        DecrementAmmo();
        RaycastHit rh;
        Vector3    dest;
        Shootable  target = null;

        Physics.Raycast(ray, out rh, float.MaxValue);
        if (rh.collider != null)
        {
            dest   = rh.point;
            target = rh.collider.gameObject.GetComponent <Shootable>();
        }
        else
        {
            dest = ray.origin + 1000 * ray.direction;
        }
        var bullet = (GameObject)GameObject.Instantiate(m_bulletPrefab);
        var lr     = bullet.GetComponent <LineRenderer>();

        bullet.transform.parent        = m_muzzleExit;
        bullet.transform.localPosition = Vector3.zero;
        bullet.transform.localRotation = Quaternion.identity;
        lr.SetPosition(1, bullet.transform.InverseTransformPoint(dest));
        lr.SetVertexCount(2);
        m_audio.Play();

        yield return(new WaitForSeconds(0.1f));

        if (target != null)
        {
            target.ShotBy(m_player == null ? gameObject : m_player.gameObject, rh.point, m_damage);
        }

        Destroy(bullet);

        if (m_shotDelay > 0)
        {
            yield return(new WaitForSeconds(m_shotDelay));
        }

        m_firing = false;
    }
示例#30
0
    private void HandleWeaponFired()
    {
        Ray _ray     = new Ray(_raycastStartPoint.position, _raycastStartPoint.forward);
        var hitInfos = Physics.RaycastAll(_ray, _fireDistance).OrderBy(t => t.distance); //this considers everything, but once it finds the closest it shoots, it breaks out of the loop so only one object is really hit

        foreach (var hit in hitInfos)
        {
            Shootable shootable = hit.collider.GetComponent <Shootable>();
            if (shootable != null)
            {
                shootable.TakeShot(hit);
                Debug.DrawRay(hit.point, hit.normal, Color.green, 10f);
                break;
            }
        }
    }
示例#31
0
    private void Shoot()
    {
        float angle = ShotAngle;

        if (Target)
        {
            Vector2 path = Target.transform.position - transform.position;
            angle = Vector2.SignedAngle(transform.up, path);
        }

        ShotPrefab.transform.rotation = Quaternion.AngleAxis(angle, transform.forward);

        Shootable shot = Instantiate(ShotPrefab);

        shot.transform.position = transform.position;
    }
示例#32
0
    void Shoot()
    {
        //make sure that the prefab orientation is preserved
        Quaternion ammoRotation = baseAmmoRotation;
        Shootable  shot         = (Shootable)Instantiate(loadedAmmo, transform.position, ammoRotation);

        //shoot in the direction the weapon is facing
        shot.Shoot(Vector3.Normalize(transform.forward));
        ammoStorage.ConsumeAmmo(loadedAmmo.ammoType, 1);

        //play shooting sound
        if (PlayerPrefs.GetInt(PlayerPrefKeys.MUTE) != 1)
        {
            audio.Play();
        }
    }
示例#33
0
    private void OnTriggerEnter(Collider other)
    {
        Shootable bullet = other.gameObject.GetComponent<Shootable>();
        if (bullet != null)
        {

            foreach (Rigidbody rb in GetComponentsInChildren<Rigidbody>())
            {
                if (rb.gameObject == this.gameObject)
                    continue;
                rb.isKinematic = false;
            }
            Explode();
            this.DoAfterSeconds(4f, false, ReturnToFactory);

        }
    }
示例#34
0
    // Use this for initialization
    void Start()
    {
        if (bombTarget == null)
        {
            bombTarget = GameObject.Find("HandbombTarget").transform;
        }
        if (shootable == null)
        {
            shootable = GetComponent<Shootable>();
        }
        //LeanTween.rot(gameObject, new Vector3(0, 0, 180), rotateTime).setRepeat(10); ;
        iTween.RotateBy(gameObject, iTween.Hash("amount", new Vector3(0, 0, 30), "time", rotateTime, "looptype", iTween.LoopType.loop, "easetype", iTween.EaseType.linear));

        LeanTween.scale(gameObject, new Vector3(1.5f, 1.5f, 1.5f), scaleTime);
        //Vector3[] pts = new Vector3[3];
        //pts[2] = transform.position + new Vector3(0, 1, 0);
        //pts[0] = bombTarget.position;
        //pts[1] = (pts[0] + pts[2]) / 2;
        
        LeanTween.move(gameObject, bombTarget.position, scaleTime).setEase(LeanTweenType.easeInExpo).setOnComplete(OnMoveComplete);
    }
示例#35
0
    void Start()
    {
        rmData = GetComponent<RadarManager>();
        rocketHUD = GameObject.Find ("fake weapon hud").GetComponent<Image>();;
        rocketHUD.gameObject.SetActive(true);
        SpeedReadout = GameObject.Find("Speed");
        throttleReadout = GameObject.Find("Throttle");

        if(optionalDangerHeightReadout) {
            dangerBaseText = optionalDangerHeightReadout.text;
        }

        mFlash = GetComponent<MuzzleFlash>();
        mFlash.Reset();
        StartCoroutine(rocketSalvoRelease());
        shootableScript = GetComponent<Shootable>();
        wasHealth = startHealth = shootableScript.healthLimit;
        UI_ThrottleReadout = throttleReadout.GetComponent<UI_Speed> ();
        UI_SpeedReadout = SpeedReadout.GetComponent<UI_Speed> ();

        hardpointRef = missionTarget.GetComponentInChildren<HardPointCounter>();

        hardpointMax = hardpointRef.hardpointCount;
    }
示例#36
0
    void Start()
    {
        mFlash = GetComponent<MuzzleFlash>();
        mFlash.Reset();
        StartCoroutine(rocketSalvoRelease());
        shootableScript = GetComponent<Shootable>();
        wasHealth = startHealth = shootableScript.healthLimit;

        hardpointRef = missionTarget.GetComponentInChildren<HardPointCounter>();

        hardpointMax = hardpointRef.hardpointCount;
    }
	public void Awake()
	{
		m_Weapon = GetComponent<Shootable>();
	}