コード例 #1
0
    void OnTriggerEnter2D(Collider2D otherCollider)
    {
        // Is this a shot?
        ShotScript shot = otherCollider.gameObject.GetComponent <ShotScript>();

        if (shot != null)
        {
            // Avoid friendly fire
            if (shot.isEnemyShot != isEnemy)
            {
                Damage(shot.damage);

                // Destroy the shot
                Destroy(shot.gameObject);
            }
        }

        DamageScript damage1 = otherCollider.gameObject.GetComponent <DamageScript>();

        if (damage1 != null)
        {
            if (damage1.isEnemyShot != isEnemy)
            {
                Damage(damage1.damage);
            }
        }
    }
コード例 #2
0
    private void CheckDamage(GameObject other)
    {
        // Deals damage if it is one of the damageTags
        if (lastDamaged >= damageCooldown && damageTags.Contains(other.tag))
        {
            DamageScript dmgScript = other.GetComponent <DamageScript>();
            if (dmgScript != null)
            {
                // Take Damage
                Debug.Log("hit");
                InflictDamage(dmgScript.damage);
                lastDamaged = 0.0f;

                // Trigger damaged animation
                if (anim != null)
                {
                    anim.SetTrigger(damageHash);
                }
            }
            else
            {
                Debug.LogWarning(gameObject.name + " should take damage, but the damaging object, " + other.name + " has no DamageScript attached to it.");
            }
        }
    }
コード例 #3
0
    private bool playerFound = false;                               //tell if player is in range or not

    // Use this for initialization
    protected virtual void Start()
    {
        damageScript = GetComponent <DamageScript>();                        //get the component
        scaleX       = transform.localScale.x;                               //set the varible value
        currentTime  = 0;                                                    //set current time to zero
        playerTarget = GameObject.FindGameObjectWithTag("Player").transform; //get player reference
    }
コード例 #4
0
    // Use this for initialization
    void Start()
    {
        gunCoolDown            = 0;                                         //at start we want it to zero so player can immideatly fire
        currentImmuneTime      = 0;                                         //at start we want it to zero so player can get hurt
        currentlayerChangeTime = layerChangeTime;
        myBody       = GetComponent <Rigidbody2D>();                        //get the component
        anim         = GetComponent <Animator>();                           //get the component
        damageScript = GetComponent <DamageScript>();                       //get the component
        GameManager.instance.playerDead    = false;                         //set dead to false
        GameManager.instance.levelComplete = false;                         //set level complete to false

        speed = 3 + 0.5f * GameManager.instance.speed;                      //set the speed
        if (speed > 8)
        {
            speed = 8;                                                      //if speed is more than 8 we set it to 8
        }
        gunFireRate = 1f - 0.2f * GameManager.instance.gunFireRate;         //set gunFireRate
        if (gunFireRate < 0.2f)
        {
            gunFireRate = 0.2f;                                             //if gunFireRate is less than 0.2f , we set it to 0.2f
        }
        gunDamage = GameManager.instance.gunDamage;                         //set gun damage

#if MOBILE_INPUT
        usingKeyboard = false;
#else
        usingKeyboard = true;
#endif
    }
コード例 #5
0
    /*
     * Using the DamageScript class, when the enemy laser hits the player, its health will be reduced accordingly. When the
     * players health reaches zero, the player game object is destroyed. If a gameobject collides with our player ship,
     * that object will also be destroyed, like the laser.
     *
     * Null reference error here??
     */

    private void OnTriggerEnter2D(Collider2D collision)
    {
        DamageScript local_damageScript = collision.gameObject.GetComponent <DamageScript>();

        if (local_damageScript == false)
        {
            return;
        }

        field_int_playerHealth -= local_damageScript.GetFieldIntDamage();

        field_dob_percentage = (field_int_playerHealth) / (field_dob_playerHealthCopy) * 100;
        //Debug.Log(field_dob_percentage);

        local_damageScript.Destroy();
        triggerHitSound();

        if (field_int_playerHealth <= 0)
        {
            FindObjectOfType <LevelLoadingScript>().LoadGameOverScreen();
            Destroy(gameObject);
            triggerDeathAnimation();
            triggerDeathSound();
        }
    }
コード例 #6
0
    private Transform playerTarget;                                                     //ref to target

    // Use this for initialization
    void Start()
    {
        playerTarget      = GameObject.FindGameObjectWithTag("Player").transform;   //get reference to the player
        currentAttackTime = attackTime;                                             //set the attack time
        currentIdleTime   = idleTime;                                               //set the idle time
        damageScript      = GetComponent <DamageScript>();                          //get component
        anim = GetComponent <Animator>();                                           //get component
    }
コード例 #7
0
ファイル: Minigun.cs プロジェクト: Shirzay/git-sum
    public void DoDamage(Collider c)
    {
        if (c.gameObject.tag == "Enemy")
        {
            DamageScript ds = c.gameObject.GetComponent <DamageScript>();

            ds.AddDamage(damage);
        }
    }
コード例 #8
0
ファイル: EnemyScript.cs プロジェクト: Shadowtyu/Darwin-Game
 // Use this for initialization
 public new virtual void Start()
 {
     base.Start();
     anim          = GetComponentInChildren <Animator> ();
     rBody         = GetComponent <Rigidbody>();
     player        = GameObject.FindGameObjectWithTag("Player");
     _DamageScript = player.GetComponent <DamageScript>();
     stunSpawnOnce = true;
 }
コード例 #9
0
 private void Start()
 {
     _attackCooldown = 0f;
     // init needed scripts
     _player           = GameObject.Find("PlayerHans");
     _projectileScript = projectilePrefab.GetComponent <ProjectileScript>();
     _damageScript     = projectilePrefab.GetComponent <DamageScript>();
     _audioData        = GetComponent <AudioSource>();
 }
コード例 #10
0
 public override void damageProc(DamageScript scr)
 {
     if (scr == null)
         return;
     hp -= scr.getDamage();
     if(hp < 1)
     {
         GameManager.gameOver();
     }
 }
コード例 #11
0
 public void ShootRay()
 {
     if (Physics.Raycast(transform.position, transform.forward, out hit, 1000, layerMask))
     {
         DamageScript damageScript = hit.collider.gameObject.GetComponent <DamageScript>();
         if (damageScript != null)
         {
             //damageScript.HealthPoints -= 25;
         }
     }
 }
コード例 #12
0
    void Start()
    {
        if (cam == null)
        {
            Debug.LogError("PlayerShoot: No camera referenced!");
            this.enabled = false;
        }

        inventory = GetComponentInChildren <Inventory>();

        _damageScript = GetComponent <DamageScript>();
    }
コード例 #13
0
 public override void damageProc(DamageScript scr)
 {
     if (scr == null)
     {
         return;
     }
     hp -= scr.getDamage();
     if (hp < 1)
     {
         GameManager.gameOver();
     }
 }
コード例 #14
0
    private float x = 0;                                                    //this is to increase the beam size with time

    // Use this for initialization
    void Start()
    {
        anim              = GetComponent <Animator>();                      //get the component
        damageScript      = GetComponent <DamageScript>();                  //get the component
        scaleX            = transform.localScale.x;                         //set the scale
        currentIdleTime   = idleTime;                                       //set idle time
        currentAttackTime = attackTime;                                     //set attack time
        alienMode         = AlienMode.idle;                                 //set mode
        movingRight       = false;                                          //moving right is false at start
        target            = leftEnd.position;                               //at start target is left end
        currentCoolDown   = 0;                                              //cool down time is zero
    }
コード例 #15
0
    private void OnTriggerEnter2D(Collider2D collision)
    {
        DamageScript local_damageScript = collision.gameObject.GetComponent <DamageScript>();

        field_float_health -= local_damageScript.GetFieldIntDamage();
        local_damageScript.Destroy();
        if (field_float_health <= 0)
        {
            Destroy(gameObject);
            triggerDeathAnimation();
            triggerDeathSound();
        }
    }
コード例 #16
0
    void ShootGun()
    {
        RaycastHit hit;

        if (Physics.Raycast(fpsCam.transform.position, fpsCam.transform.forward, out hit, range))
        {
            DamageScript target = hit.transform.GetComponent <DamageScript>();
            if (target != null)
            {
                target.TakeDamage(damage);
            }
        }
    }
コード例 #17
0
    private void OnCollisionEnter(Collision collision)
    {
        DamageScript ds = collision.gameObject.GetComponent <DamageScript>();

        if (ds)
        {
            Health -= ds.Damage;

            if (Health <= 0)
            {
                Debug.Log("Killing off " + name);
                GetComponent <OnDeathScript>().PerformDeathActionAndDestroy();
            }
        }
    }
コード例 #18
0
    private bool playerInRange = false;                                 //check if player is in range or not

    // Use this for initialization
    void Start()
    {
        gunCoolDown  = 0;                                                               //set it to zero
        playerTarget = GameObject.FindGameObjectWithTag("Player");                      //get the player
        anim         = GetComponent <Animator>();                                       //get the component
        damageScript = GetComponent <DamageScript>();                                   //get the component
        scaleX       = transform.localScale.x;                                          //set the scale x value
        if (movingRight)
        {
            target = rightEnd.position;                                                 //depending on direction set the target
        }
        else if (!movingRight)
        {
            target = leftEnd.position;
        }
    }
コード例 #19
0
ファイル: RedGolemController.cs プロジェクト: Kakoure/ISPGame
 void Slash()
 {
     attackObject = Instantiate(dmgObject, transform);
     attackvars   = attackObject.GetComponent <DamageScript>();
     if (facingRight)
     {
         kbForce  = 8f;
         lungeDir = 1;
     }
     else
     {
         kbForce  = -8f;
         lungeDir = -1;
     }
     attackvars.Setup(damage, kbForce, "Evil", new Vector2(1.75f, 0.9f), new Vector2(0.5f, 0f), 4, 45f * lungeDir);
     rg2d.AddForce(new Vector2(10f * lungeDir, 0f), ForceMode2D.Impulse);
 }
コード例 #20
0
 public override void Start()
 {
     _playerInfo = GameObject.FindGameObjectWithTag("Info").GetComponent <PlayerInfo>();
     base.Start();
     gameObject.transform.eulerAngles = ResetEuler;
     _damageScript = GetComponentInChildren <DamageScript>();
     hitPoints     = _playerInfo.life;
     rBody         = GetComponent <Rigidbody>();
     anim          = GetComponentInChildren <Animator>();
     _cameraScript = GameObject.FindGameObjectWithTag("MainCamera").GetComponent <CameraScript>();
     //Verifica se o loading terminou
     if (loaded == true)
     {
         anim.SetBool("loaded", true);
         Cinematic      = true;
         rBody.velocity = new Vector3(10, 5, 0);
     }
 }
コード例 #21
0
 public override void damageProc(DamageScript scr)
 {
     if (scr == null)
         return;
     hp -= scr.getDamage();
     if(hp < 1 & !death)
     {
         death = true;
         if (gameObject.GetComponent<KaboonScript>() != null)
         {
             gameObject.GetComponent<KaboonScript>().setKaboon();
         }
         //爆発アニメーション
         explosion();
         //スコアに追加
         GameManager.Score += score;
     }
 }
コード例 #22
0
 void Start()
 {
     GetComponent <BoxCollider>().isTrigger = true;
     _EV = GameDataContainer.Instance.GDC.EnemyValues.Find(o => o.Name == UnitName);
     if (_EV != null)
     {
         _DS = new DamageScript(_EV.Health, OnDeath);
         Debug.Log(_EV.Personality);
         if (_EV.Personality)
         {
             PickPersonality();
         }
     }
     else
     {
         Debug.LogWarning("NO DATA FOUND");
         Destroy(this.gameObject);
     }
 }
コード例 #23
0
        public void ReleaseFireBall()
        {
            BaseSkillInfo.OnCoolDown = false;

            if (gameObject.CompareTag("Enemy"))
            {
                BaseSkillInfo.SkillObjects[0].transform.LookAt(BaseSkillInfo.TargetEnemy.transform.position);
            }

            BaseSkillInfo.SkillObjects[0].GetComponent <Rigidbody>().AddForce(BaseSkillInfo.SkillObjects[0].transform.forward * 500);

            DamageScript DmgScript = BaseSkillInfo.SkillObjects[0].AddComponent <DamageScript>();

            DmgScript.TargetTag  = BaseSkillInfo.TargetTag;
            DmgScript.Attack     = BaseSkillInfo.PlayerStats.ATK;
            DmgScript.DamageType = BaseSkillInfo.DamageType;

            Destroy(BaseSkillInfo.SkillObjects[0], 10.0f);
        }
コード例 #24
0
 public override void damageProc(DamageScript scr)
 {
     if (scr == null)
     {
         return;
     }
     hp -= scr.getDamage();
     if (hp < 1 & !death)
     {
         death = true;
         if (gameObject.GetComponent <KaboonScript>() != null)
         {
             gameObject.GetComponent <KaboonScript>().setKaboon();
         }
         //爆発アニメーション
         explosion();
         //スコアに追加
         GameManager.Score += score;
     }
 }
コード例 #25
0
 private void FixedUpdate()
 {
     if (rg2d.velocity.x > 0f && !facingRight)
     {
         Flip();
     }
     else if (rg2d.velocity.x < 0f && facingRight)
     {
         Flip();
     }
     hitCheck = Physics2D.OverlapCircle(hitboxOrigin.position, 0.1f, whatHitsThis);
     if (hitCheck && !hasHit)
     {
         anim.SetBool("hit", true);
         hasHit     = true;
         attackObj  = Instantiate(dmgObject, transform);
         attackvars = attackObj.GetComponent <DamageScript>();
         attackvars.Setup(damage, knockback * Mathf.Sign(rg2d.velocity.x), "Evil", new Vector2(.02f, .02f), new Vector2(0.1f, 0.01f), 1, 10f * Mathf.Sign(rg2d.velocity.x));
         trailParticles.Stop();
         hitParticles = Instantiate(hitParticlesObj, transform).GetComponent <ParticleSystem>();
         hitParticles.transform.position = transform.position;
     }
 }
コード例 #26
0
    void SlapLunge()
    {
        attackObj     = Instantiate(damageObj, transform);
        attackvars    = attackObj.GetComponent <DamageScript>();
        rg2d.velocity = new Vector2(0f, 0f);
        if (facingRight)
        {
            //rg2d.AddForce(new Vector2(lungePower, 0));
            if (!anim.GetBool("Combo"))
            {
                float kbAngle = 45f;
                attackvars.Setup(10f, 4f, "Good", new Vector2(1.3f, 0.6f), new Vector2(0.4f, -0.2f), 1, kbAngle);
            }
            else
            {
                float kbAngle = 45f;
                attackvars.Setup(10f, 16f, "Good", new Vector2(1.3f, 0.6f), new Vector2(0.4f, -0.2f), 1, kbAngle);
            }
        }

        if (!facingRight)
        {
            //rg2d.AddForce(new Vector2(-lungePower, 0));
            if (!anim.GetBool("Combo"))
            {
                float kbAngle = -45f;
                attackvars.Setup(10f, -4f, "Good", new Vector2(1.3f, 0.6f), new Vector2(0.4f, -0.2f), 1, kbAngle);
            }
            else
            {
                float kbAngle = -45f;
                //Debug.Log(kbAngle);
                attackvars.Setup(10f, -16f, "Good", new Vector2(1.3f, 0.6f), new Vector2(0.4f, -0.2f), 1, kbAngle);
            }
        }
        attackObj.transform.SetParent(transform);
    }
コード例 #27
0
    private void OnTriggerEnter2D(Collider2D collision)
    {
        DamageScript local_damageScript = collision.gameObject.GetComponent <DamageScript>();

        field_float_health -= local_damageScript.GetFieldIntDamage();
        local_damageScript.Destroy();
        triggerHitSound();

        if (gameObject.tag == "Endboss" && field_float_health <= 0)
        {
            FindObjectOfType <LevelLoadingScript>().LoadLevel2();
            Destroy(gameObject);
            triggerDeathAnimation();
            triggerDeathSound();
            addScorePoints();
        }
        if (field_float_health <= 0)
        {
            Destroy(gameObject);
            triggerDeathAnimation();
            triggerDeathSound();
            addScorePoints();
        }
    }
コード例 #28
0
    /*
     * Methods called by animations.
     */

    public void SpawnDamage()
    {
        DamageScript.SpawnDamage(damagePoint.position, damageRadius, 1, health);
    }
コード例 #29
0
ファイル: IsDamageScript.cs プロジェクト: ETeamGames/RunGame
 public abstract void damageProc(DamageScript scr);
コード例 #30
0
 private void Start()
 {
     _player             = GameObject.Find("PlayerHans");
     _damageScript       = GetComponent <DamageScript>();
     _moveZombieToPlayer = GetComponent <MoveCharacterToPlayer>();
 }
コード例 #31
0
 // Use this for initialization
 void Start()
 {
     smokeParticle = transform.GetComponent <ParticleSystem>();
     hpRef         = transform.parent.GetComponentInChildren <DamageScript>();
     hpRefMikko    = transform.parent.GetComponentInChildren <DamageScriptMikko>();
 }
コード例 #32
0
 public void Awake()
 {
     damageScript = this.GetComponent <DamageScript>();
 }
コード例 #33
0
ファイル: IsDamageScript.cs プロジェクト: x13david/RunGame
 public abstract void damageProc(DamageScript scr);