private void FigureOutScore(Vector3 hitPosition)
    {
        float distanceFromCenter = Vector3.Distance(transform.position, hitPosition);
        int   score = 0;

        if (distanceFromCenter < 0.1f)
        {
            score = 50;
        }
        else if (distanceFromCenter < 0.2f)
        {
            score = 25;
        }
        else if (distanceFromCenter < 0.3f)
        {
            score = 10;
        }
        else if (distanceFromCenter < 0.4f)
        {
            score = 5;
        }
        else if (distanceFromCenter < 0.5f)
        {
            score = 1;
        }

        OnHit.Invoke(score);
    }
Exemple #2
0
    void FixedUpdate()
    {
        if (hasHit)
        {
            return;
        }

        var delta = transform.forward * (Time.fixedDeltaTime * speed);
        var ray   = new Ray(transform.position, delta);

        if (Physics.Raycast(ray, out var hit, Time.fixedDeltaTime * speed, collisionMask, QueryTriggerInteraction.Ignore))
        {
            StopCoroutine(lifetimeRoutine);
            lifetimeRoutine = null;

            StartCoroutine(KillRoutine(disappearanceTime));
            soundEffect.Play(0);

            var hittable = hit.transform.GetComponent <IHittable>();
            hittable?.Hit(this, hit);

            onHit.Invoke(hit);
            transform.position = hit.point;

            hasHit = true;
        }
    void OnHit(float damage, Transform hitTransform)
    {
        if (hitTransform == transform)
        {
            currentHealth -= damage;
            HitEvent.Invoke(this);
        }

        if (currentHealth <= 0f)
        {
            isDead = true;

            if (explosionObject != null)
            {
                Instantiate(explosionObject, transform.position, transform.rotation);
            }

            SoundManager.instance.PlaySound(explosionSound);

            SoundManager.instance.StopSound(engineIdleSound);
            SoundManager.instance.StopSound(engineThrottleSound);
            SoundManager.instance.StopSound(engineDethrottleSound);

            OnDestroy();
        }
    }
        /// <summary>
        /// Casts a ray from the <see cref="source"/> origin location towards the <see cref="target"/> destination location and determines whether the raycast is blocked by another <see cref="Collider"/>.
        /// </summary>
        public virtual void Process()
        {
            Vector3 difference = target.transform.position - source.transform.position;
            Ray     ray        = new Ray(source.transform.position, difference);

            RaycastHit[] raycastHits = PhysicsCast.RaycastAll(
                physicsCast,
                ray,
                difference.magnitude,
                Physics.IgnoreRaycastLayer);
            bool isObscured = raycastHits.Any(hit => hit.transform.gameObject != source && hit.collider != target);

            if (isObscured == wasPreviouslyObscured)
            {
                return;
            }

            wasPreviouslyObscured = isObscured;

            if (isObscured)
            {
                TargetObscured?.Invoke(raycastHits);
            }
            else
            {
                TargetUnobscured?.Invoke();
            }
        }
    public void VecIn(SpacebrewClient.SpacebrewMessage message)
    {
        Debug.Log("got message");
        Debug.Log(message.valueNode);
        SimpleJSON.JSONArray arr = message.valueNode.AsArray;
        //switching from Z up to Unity's Y up
        prevDir.x = arr[0].AsFloat;
        prevDir.z = arr[1].AsFloat;
        prevDir.y = arr[2].AsFloat;
        if (applyTransform)
        {
            if (!invTransform)
            {
                prevDir = transform.rotation * prevDir;
            }
            else
            {
                prevDir = Quaternion.Inverse(transform.rotation) * prevDir;
            }
        }
        //lets assume sounds happen 1m above the ground
        Plane plane = new Plane(Vector3.up, Vector3.up);
        Ray   ray   = new Ray(transform.position, prevDir);
        float hitAt = 0;

        if (plane.Raycast(ray, out hitAt))
        {
            hit = ray.origin + ray.direction * hitAt;
            onLocalized.Invoke(hit);
        }
    }
Exemple #6
0
    /// <summary>
    /// Detects collision with a ball to aim the ball
    /// </summary>
    /// <param name="coll">collision info</param>

    void OnCollisionEnter2D(Collision2D coll)
    {
        if (coll.gameObject.CompareTag("Ball") && Frontcollision(coll))
        {
            AudioManager.Play(AudioClipName.PaddleCollide);
            // HUD.AddHits()
            hitEvent.Invoke(side, coll.gameObject.GetComponent <Ball>().Hits);
            // calculate new ball direction
            float ballOffsetFromPaddleCenter =
                coll.transform.position.y - transform.position.y;
            float normalizedBallOffset = ballOffsetFromPaddleCenter /
                                         half_height;
            float angleOffset = normalizedBallOffset * BounceAngleHalfRange;
            // angle modification is based on screen side
            float angle;
            if (side == ScreenSide.Left)
            {
                angle = angleOffset;
            }
            else
            {
                angle = (float)(Mathf.PI - angleOffset);
            }
            Vector2 direction = new Vector2(Mathf.Cos(angle), Mathf.Sin(angle));
            // tell ball to set direction to new direction
            Ball ballScript = coll.gameObject.GetComponent <Ball>();
            ballScript.SetDirection(direction);
        }
    }
Exemple #7
0
 public void OnHitEvent()
 {
     if (HitEvent != null)
     {
         HitEvent.Invoke();
     }
 }
Exemple #8
0
 private void OnTriggerEnter(Collider other)
 {
     if (other.CompareTag("Enemy"))
     {
         HitEvent.Invoke(other.gameObject);
     }
 }
Exemple #9
0
 public void Hitted(GameObject victem)
 {
     if (HitEvent != null)
     {
         HitEvent.Invoke(victem, parent, this);
     }
 }
 public void OnHit(HitBox hitbox, Collider collider)
 {
     if (canApplyDamage)
     {
         onHitDamage.Invoke(new HitInfo(hitbox, transform.position, characterManager, null));
     }
 }
Exemple #11
0
        virtual protected void OnTriggerEnter(Collider other)
        {
            Damageable oppDamageable = other.GetComponent <Damageable>();

            if (oppDamageable)
            {
                bool touched = oppDamageable.TakeDamage(this, m_currData.damage, m_attackID);
                if (!touched)
                {
                    return;
                }

                if (other.gameObject.layer == LayerMask.NameToLayer("EnemyHitBox"))
                {
                    OnHitEvent.Invoke(m_firstHit, m_currData.damage);
                }

                m_firstHit = false;

                ManageFXObject(other.gameObject);

                if (!oppDamageable.IsAlive())
                {
                    return;
                }

                BasicMovement mvmt = other.gameObject.GetComponentInParent <BasicMovement>();
                if (mvmt)
                {
                    ManageCrowdControlEffect(mvmt);
                }
            }
        }
Exemple #12
0
 void Update()
 {
     if (Input.GetMouseButtonDown(0))
     {
         DoHit?.Invoke(Physics2D.Raycast(_camera.ScreenToWorldPoint(Input.mousePosition), Vector2.zero));
     }
 }
    void OnHit(float damage, Transform hitTransform)
    {
        if (hitTransform == transform)
        {
            currentHealth -= damage;
            if (currentHealth > 0f)
            {
                HitEvent.Invoke(this);
            }
        }

        if (currentHealth <= 0f)
        {
            if (explosionObject != null)
            {
                GameObject explosion = Instantiate(explosionObject);
                explosion.transform.position = transform.position;
            }

            SoundManager.instance.PlaySound(explosionSound);

            if (DestroyEvent != null)
            {
                DestroyEvent.Invoke(this);
            }

            OnDestroy();
        }
    }
Exemple #14
0
		void OnTriggerEnter(Collider other)
		{
			if (other.CompareTag("Enemy"))
			{
				HitEvent?.Invoke(this, true);
				SimplePool.Despawn(gameObject);
			}
		}
Exemple #15
0
		void OnTriggerExit(Collider other)
		{
			if (!other.CompareTag("Boundary"))
				return;

			HitEvent?.Invoke(this, false);
			SimplePool.Despawn(gameObject);
		}
Exemple #16
0
    void OnTriggerEnter(Collider collision)
    {
        EnemyHealth enemyHealth = collision.gameObject.GetComponent <EnemyHealth>();

        if (enemyHealth)
        {
            onHit.Invoke(enemyHealth);
        }
    }
    void OnHit(Transform hitTransform)
    {
        if (HitEvent != null)
        {
            HitEvent.Invoke(damage, hitTransform);
        }

        Destroy(gameObject);
    }
 void OnTriggerEnter(Collider other)
 {
     if (other.isTrigger)
     {
         if (EventHit != null)
         {
             EventHit.Invoke();
         }
     }
 }
Exemple #19
0
 private void OnTriggerEnter2D(Collider2D other)
 {
     if (other.CompareTag("Enemy"))
     {
         HitEvent.Invoke(other.gameObject);
         Destroy();
     }
     else if (other.CompareTag("Wall"))
     {
         Destroy();
     }
 }
Exemple #20
0
 private void OnCollisionEnter2D(Collision2D other)
 {
     if (other.collider.CompareTag("Enemy"))
     {
         HitEvent.Invoke(other.gameObject);
         Destroy();
     }
     else if (other.collider.CompareTag("Wall") || other.collider.CompareTag("Ground"))
     {
         Destroy();
     }
 }
Exemple #21
0
        void Hit(GameObject objHit, Vector3 pos, Vector3 normal)
        {
            HitEvent?.Invoke(objHit, pos, normal);

            var organ = objHit.GetComponent <Organ>();

            if (organ != null)
            {
                organ.DoDamage(_gameObj, _damage, pos, normal);
            }

            Destroy(_gameObj);
        }
Exemple #22
0
    private void OnTriggerEnter2D(Collider2D collision)
    {
        if (collision.gameObject.CompareTag("Knife"))
        {
            isShaking = true;

            Invoke("StopShaking", 0.1f);

            countHitsInPum += 1;

            HitEvent.Invoke();
        }
    }
        private void HandelShooting()
        {
            if (Time.time <= CooldownCollapsed)
            {
                return;
            }


            var ray = new Ray(AimOrigin.transform.position, WeaponSocket.transform.forward);

            if (Physics.Raycast(ray, out m_raycastHit, Mathf.Infinity, Weapon.HitMask,
                                QueryTriggerInteraction.Ignore))
            {
                if (PhotonView.IsMine)
                {
                    var target = m_raycastHit.transform.GetComponent <IDamageable>();

                    if (PlayerHelper.ValidateTarget(m_raycastHit.transform.gameObject))
                    {
                        var hitted = target.ApplyDamage(Weapon.Damage);
                        if (hitted)
                        {
                            HitEvent.Invoke();
                            ScriptableTextDisplay.Instance.InitializeStackingScriptableText(1, m_raycastHit.point,
                                                                                            Weapon.Damage.ToString(),
                                                                                            m_raycastHit.transform
                                                                                            .gameObject
                                                                                            .name);
                        }
                    }
                }
            }

            if (PhotonView.IsMine)
            {
                PushBack();
                ReduceAmmo();
                CameraShake.StartShake(Weapon.ShakeProfile);
            }

            var hitPoint = m_raycastHit.point == new Vector3(0, 0, 0)
                                ? MuzzleFlash.transform.position + WeaponSocket.transform.forward * 200
                                : m_raycastHit.point;

            ShootEffect(hitPoint);
            CooldownCollapsed = Time.time + Weapon.FireRate;
        }
Exemple #24
0
        public void CheckTargetHit()
        {
            m_HitColliderList.Clear();
            if (AttackCollider.OverlapCollider(m_ContactFilter, m_HitColliderList) > 0)
            {
                foreach (Collider2D col in m_HitColliderList)
                {
                    Hitable hit = col.GetComponent <Hitable>();
                    if (hit != null)
                    {
                        hit.OnTakeHit.Invoke(this);
                    }
                }

                OnHit.Invoke(this);
            }
        }
Exemple #25
0
    private void OnCollisionEnter(Collision collision)
    {
        if (_isHit)
        {
            return;
        }

        GameObject gameObject = collision.gameObject;

        Dart dart = gameObject.GetComponentInParent <Dart>();

        if (dart != null)
        {
            Vector3 point = collision.GetContact(0).point;
            _isHit = true;
            int score = GetScoreFromPoint(point);
            HitEvent?.Invoke(this, score);
        }
    }
Exemple #26
0
    private void FigureOutScore(Vector3 hitPosition)
    {
        float distanceFromCenter = Vector3.Distance(transform.position, hitPosition);
        int   score = 0;

        if (distanceFromCenter < 0.25f)
        {
            score = 15;
        }

        else if (distanceFromCenter < 0.5f)
        {
            score = 5;
        }

        // invoke is used for events, asks for integer value

        onHit.Invoke(score);
    }
Exemple #27
0
        public void TakeDamage(float damage)
        {
            if (_personAnimator.IsDead == false && _personAnimator.IsJumping == false)
            {
                HealthParameter.Value -= damage;
                HitEvent.Invoke(damage);
                if (HealthParameter.Value <= 0)
                {
                    _personAnimator.DeadAnimation();
                    Destroy(GetComponent <Collider2D>());
                    if (DeadEvent != null)
                    {
                        DeadEvent.Invoke(this, new EventArgs());
                    }

                    Destroy(gameObject, 5f);
                }
            }
        }
Exemple #28
0
 private void OnCollisionEnter2D(Collision2D collision)
 {
     if (collision.gameObject.CompareTag("Enemy") && gameObject.CompareTag("PlayerBullet"))
     {
         collision.gameObject.GetComponent <Enemy>().TakeDamage(damage);
         Destroy(gameObject);
         enemyHitEvent.Invoke(isEmpowered);
     }
     else if (collision.gameObject.CompareTag("Player") && gameObject.CompareTag("EnemyBullet"))
     {
         collision.gameObject.GetComponent <Player>().TakeDamage(damage);
         Destroy(gameObject);
     }
     else if (collision.gameObject.CompareTag("Player") && gameObject.CompareTag("PlayerBullet"))
     {
         return;
     }
     Destroy(gameObject);
 }
Exemple #29
0
        internal void WhenHit(string playerName, Coordinate location)
        {
            Hull[location].Status = TileStatus.Hit;
            OnHit?.Invoke(playerName, location);

            if (Hull.Any(x => x.Value.Status != TileStatus.Hit))
            {
                return;
            }

            //Ship sinks if all tiles in the Hull have been hit
            foreach (var tile in Hull.Values)
            {
                tile.Status = TileStatus.Sunk;
            }

            Sunken = true;
            OnSinking?.Invoke(playerName);
        }
    void Update()
    {
        mTrans.position += mTrans.forward * speed * Time.deltaTime;
        if (target == null)
        {
            return;
        }
        currentTime += Time.deltaTime;
        var coef = lerpAnim.Evaluate(currentTime / lerpTime);
        var dir  = target.position - mTrans.position;

        mTrans.forward = Vector3.Slerp(mTrans.forward, dir.normalized, coef).normalized;
        if (currentTime >= noHitTime && dir.magnitude < hitRange)
        {
            onHitTarget.Invoke(itemEffect, target);
            onHitMissile.Invoke(this, target);
            Destroy(gameObject);
        }
    }