Exemple #1
0
    void OnTriggerEnter2D(Collider2D collider)
    {
        if (collider.gameObject.tag == "Player")
        {
            PlayerReceiveDamage RD = collider.gameObject.GetComponent <PlayerReceiveDamage>();
            RD.currentHealth++;
            float oldScore = collider.gameObject.GetComponent <PlayerData>().score;

            collider.gameObject.GetComponent <PlayerData>().RpcUpdateScore(oldScore + 10);


            Debug.Log("touched player");
            Destroy(gameObject);
        }
        if (collider.gameObject.tag == "Bullet")
        {
            Bullet bullet = collider.gameObject.GetComponent <Bullet>();


            float oldScore = bullet.owner.GetComponent <PlayerData>().score;

            bullet.owner.GetComponent <PlayerData>().RpcUpdateScore(oldScore + 20);


            Debug.Log("touched bullet");
            Destroy(gameObject);
        }
    }
Exemple #2
0
    private void Start()
    {
        PCO = GetComponent <PlayerConnectionObject>();
        PRD = GetComponent <PlayerReceiveDamage>();

        if (isServer && playerName == "default")
        {
            playerName = "player " + new System.Random().Next(1, 100);
        }
    }
Exemple #3
0
    [Command] public void CmdGiveDamage(int amount, GameObject damageReceiver)
    {
        PlayerReceiveDamage PRD = damageReceiver.GetComponent <PlayerReceiveDamage>();

        if (!PRD)
        {
            Debug.Log("couldn't found slashed object");
            return;
        }
        Debug.Log("success in slashing player");
        PRD.lastHitby = gameObject;
        PRD.TakeDamage(amount);
    }
    void Update()
    {
        if (Time.time - lastDamageTime <= maxRecoveryTime)
        {
            // Debug.Log("damage prevented: " + (Time.time - lastDamageTime));
            return;
        }


        //Debug.Log("checking on obj");

        if (GravitySystem.instance.didObjFallOutside(transform.position))
        {
            lastDamageTime = Time.time;


            PlayableCharacter PC = GetComponent <PlayableCharacter>();
            if (PC)
            {
                // Debug.Log("player fallen outside of map");
                PlayerReceiveDamage PRD = PC.PCO.GetComponent <PlayerReceiveDamage>();
                if (PRD.isLocalPlayer)  //apply damage to parent PCO object
                //Debug.Log("giving damage to player that fell out of map");
                {
                    PRD.CmdTakeDamage(1000);
                }
                return;
            }
            EnemyRecieveDamage ERD = GetComponent <EnemyRecieveDamage>();
            if (ERD)
            {
                // Debug.Log("enemy fallen outside of map");
                if (isServer)
                {
                    ERD.takeDamageOnServer(1000);
                }
                return;
            }

            //Debug.Log("some unknown object fell outside of map");
        }
    }