Esempio n. 1
0
    private void Update()
    {
        PlayerValues player1 = PlayerValues.GetPlayer(0);

        if (player1 != null)
        {
            float x = player1.transform.position.x;
            float y = player1.transform.position.y;
            if (x > MaxX || x < MinX || y > MaxY || y < MinY)
            {
                player1.Die();
            }
        }
        PlayerValues player2 = PlayerValues.GetPlayer(1);

        if (player2 != null)
        {
            float x = player2.transform.position.x;
            float y = player2.transform.position.y;
            if (x > MaxX || x < MinX || y > MaxY || y < MinY)
            {
                player2.Die();
            }
        }
    }
Esempio n. 2
0
    private void OnTriggerEnter2D(Collider2D other)
    {
        PlayerValues player = other.gameObject.GetComponent <PlayerValues>();

        if (player != null)
        {
            player.Die();
            Destroy(gameObject, 0.5f);
        }
//        if(player == null || player.IsPlayerDead)
//        {
//            Destroy(this.gameObject);
//        }

        //if (other.gameObject.name == "Player 1")
        //{
        //    player.GetComponent<PlayerValues>().Die();
        //    Destroy(this.gameObject, 0.5f);
        //}

        //else if (other.gameObject.name == "Player 2")
        //{
        //    player2.GetComponent<PlayerValues>().Die();

        //    Destroy(this.gameObject, 0.5f);
        //}
    }
Esempio n. 3
0
    private void Update()
    {
        if (!_active)
        {
            return;
        }

        RaycastHit2D hit = Physics2D.CircleCast(_ball.transform.position, _ballRadius, _ballVelocity.normalized, _ballVelocity.magnitude * Time.deltaTime, _ballCollisionLayers);

        if (hit.collider != null)
        {
            if (_paddles.Contains(hit.collider.gameObject))
            {
                _ballVelocity = Quaternion.Euler(0.0f, 0.0f, Random.Range(_maxRandomAngle, _maxRandomAngle)) * _ballVelocity;
            }

            PlayerValues player = hit.collider.GetComponent <PlayerValues>();
            if (player != null)
            {
                player.Die();
                ResetPong();
            }
            else
            {
                _ballVelocity = Vector2.Reflect(_ballVelocity, hit.normal);
                AudioManager.PlaySound("Hit");
            }
        }

        if (_ball != null)
        {
            _ball.transform.position += (Vector3)_ballVelocity * Time.deltaTime;
        }

        foreach (GameObject paddle in _paddles)
        {
            Vector3 position = paddle.transform.position;
            position.y = _ball.transform.position.y;
            paddle.transform.position = position;
        }

        if (Time.time - _startTime > _duration)
        {
            ResetPong();
        }
    }
Esempio n. 4
0
    void Update()
    {
        for (int i = 0; i < activeMissiles.Count; ++i)
        {
            activeMissiles[i].LifeTimeConter += Time.deltaTime;
            if (activeMissiles[i].LifeTimeConter > MissileLifeTime)
            {
                missileIdToDestroy.Add(activeMissiles[i].SpawningID);
            }
            Transform targetTransform = PlayerValues.GetPlayer(activeMissiles[i].TargetID)?.transform;
            if (targetTransform != null)
            {
                Vector2 targetDir     = targetTransform.position - activeMissiles[i].MissileObj.transform.position;
                Vector2 velocityDelta = Vector2.zero;
                activeMissiles[i].Velocity = Vector2.SmoothDamp(activeMissiles[i].Velocity,
                                                                (targetDir).normalized * missileSpeed, ref velocityDelta, velocitySmoothTime);
            }
            activeMissiles[i].MissileObj.transform.position += (Vector3)activeMissiles[i].Velocity * Time.deltaTime;

            RaycastHit2D hit = Physics2D.CircleCast(activeMissiles[i].MissileObj.transform.position, activeMissiles[i].Collider.radius, activeMissiles[i].Velocity.normalized, activeMissiles[i].Velocity.magnitude * Time.deltaTime, collisionLayers);
            if (hit.collider != null)
            {
                PlayerValues Player = hit.collider.GetComponent <PlayerValues>();

                if (Player != null && Player.Id != activeMissiles[i].OwnerID)
                {
                    Player.Die();
                    missileIdToDestroy.Add(activeMissiles[i].SpawningID);
                }
            }
        }
        for (int i = activeMissiles.Count - 1; i >= 0; i--)
        {
            if (missileIdToDestroy.Contains(activeMissiles[i].SpawningID))
            {
                Destroy(activeMissiles[i].MissileObj);
                activeMissiles.RemoveAt(i);
            }
        }
        missileIdToDestroy.Clear();
    }