Esempio n. 1
0
    //TODO: Move the ship-specific logic to Ship subclasses and common logic to Ship base class
    protected virtual void OnTriggerEnter(Collider other)
    {
        //Destroy bullets upon hitting a killzone
        if (other.tag == "KillZone")
        {
            curState = BulletState.none;
            DestroyThisBullet();
        }
        //Deal damage to any other player hit
        else if (other.tag == "Player")
        {
            Ship      shipHit      = other.gameObject.GetComponentInParent <Ship>();
            Character characterHit = shipHit.character;

            if (characterHit.playerEnum != owningPlayer)
            {
                //Masochists with the shield up are immune to incoming bullets
                if (characterHit.characterType == CharactersEnum.m*******t)
                {
                    M*******t masochistHit = characterHit as M*******t;
                    if (masochistHit != null && masochistHit.masochistShip.shieldUp)
                    {
                        return;
                    }
                }

                //TODO: Re-add m*******t damage multiplier to bullet creation
                //Do damage to the player hit
                shipHit.TakeDamage(damage);

                GameObject explosion = Instantiate(explosionPrefab, other.gameObject.transform.position, new Quaternion()) as GameObject;
                Destroy(explosion, 5f);
                curState = BulletState.none;
                DestroyThisBullet();
            }
            //TODO: What the heck? Why is this thisPlayer == vampire? We should re-write this
            //If the bullet was absorbed by the vampire with it's shield up, heal slightly instead of doing damage
            else if (owningPlayer != PlayerEnum.none && thisPlayer.character.characterType == CharactersEnum.vampire)
            {
                if (curState == BulletState.absorbedByVampire)
                {
                    shipHit.TakeDamage(damage * -vampShieldHealAmount);
                    curState = BulletState.none;
                    damage   = 1;
                    DestroyThisBullet();
                }
            }
        }
        //Deal damage to any ProtagShip hit
        else if (other.tag == "ProtagShip")
        {
            DamageableObject otherShip = other.gameObject.GetComponentInParent <DamageableObject>();
            otherShip.TakeDamage(damage);

            GameObject explosion = Instantiate(explosionPrefab, other.gameObject.transform.position, new Quaternion()) as GameObject;
            Destroy(explosion, 5f);
            curState = BulletState.none;
            DestroyThisBullet();
        }
    }
Esempio n. 2
0
    IEnumerator AttackSequence()
    {
        isAttacking = true;

        Vector3 startOffset = mainHand.transform.position - attackCenter.position;

        mainHand.Reparent(!player.isFlipped, false, attackTarget);
        yield return(new WaitForSeconds(attackCooldown / 4f));

        Vector3 endOffset = mainHand.transform.position - attackCenter.position;

        //add some buffer
        Vector3 dir = endOffset - startOffset;

        RaycastHit2D[] hits = Physics2D.CircleCastAll(attackCenter.position + startOffset, 0.3f, dir.normalized, dir.magnitude, attackableLayers);
        foreach (RaycastHit2D hit in hits)
        {
            DamageableObject health = hit.collider.GetComponent <DamageableObject>();
            if (health != this)
            {
                health.TakeDamage(damage);
            }
        }

        yield return(new WaitForSeconds(attackCooldown / 4f));

        mainHand.Reparent(player.isFlipped, false);
        yield return(new WaitForSeconds(attackCooldown / 2f));

        isAttacking = false;
    }
Esempio n. 3
0
    void OnTriggerStay(Collider other)
    {
        if (other.tag == "Player")
        {
            Ship         shipHit        = other.gameObject.GetComponentInParent <Ship>();
            ShipMovement playerMovement = other.gameObject.GetComponentInParent <ShipMovement>();
            if (shipHit.playerEnum != owningPlayer)
            {
                //Do damage to the player hit
                shipHit.TakeDamage(damage);

                //Slow the player while in the beam
                playerMovement.SlowPlayer(slowingFactor);

                GameObject explosion = Instantiate(explosionPrefab, other.transform.position, new Quaternion()) as GameObject;
                Destroy(explosion, 5f);
            }
        }
        else if (other.tag == "ProtagShip")
        {
            DamageableObject otherShip = other.gameObject.GetComponentInParent <DamageableObject>();
            otherShip.TakeDamage(damage);

            GameObject explosion = Instantiate(explosionPrefab, other.transform.position, new Quaternion()) as GameObject;
            Destroy(explosion, 5f);
        }
    }
Esempio n. 4
0
 public void RemoveEnemy(DamageableObject enemy)
 {
     if (enemies.Contains(enemy))
     {
         enemy.DestroyMyGameObject();
         enemies.Remove(enemy);
     }
 }
Esempio n. 5
0
    void Update()
    {
        // Check if the player has pressed the fire button and if enough time has elapsed since they last fired
        if (Input.GetButtonDown("Fire1") && Time.time > nextFire)
        {
            // Update the time when our player can fire next
            nextFire = Time.time + fireRate;

            // Start our ShotEffect coroutine to turn our laser line on and off
            StartCoroutine(ShotEffect());

            // Create a vector at the center of our camera's viewport
            Vector3 rayOrigin = fpsCam.ViewportToWorldPoint(new Vector3(0.5f, 0.5f, 0.0f));

            // Declare a raycast hit to store information about what our raycast has hit
            RaycastHit hit;

            // Set the start position for our visual effect for our laser to the position of gunEnd
            laserLine.SetPosition(0, gunEnd.position);

            // Check if our raycast has hit anything
            if (Physics.Raycast(rayOrigin, fpsCam.transform.forward, out hit, weaponRange))
            {
                // Set the end position for our laser line
                laserLine.SetPosition(1, hit.point);

                // Get a reference to a health script attached to the collider we hit
                DamageableObject health = hit.collider.GetComponent <DamageableObject>();

                // If there was a health script attached
                if (health != null)
                {
                    // Call the damage function of that script, passing in our gunDamage variable
                    health.Damage(gunDamage, damageType);
                }
                else
                {
                    //Debug.Log("hit " + hit.collider.gameObject);
                }


                // Check if the object we hit has a rigidbody attached
                if (hit.rigidbody != null)
                {
                    // Add force to the rigidbody we hit, in the direction from which it was hit
                    hit.rigidbody.AddForce(-hit.normal * hitForce);
                }

                damageType.SpawnPrefabEffect(hit.point);
            }
            else
            {
                // If we did not hit anything, set the end of the line to a position directly in front of the camera at the distance of weaponRange
                laserLine.SetPosition(1, rayOrigin + (fpsCam.transform.forward * weaponRange));
            }
        }
    }
Esempio n. 6
0
    void OnTriggerEnter(Collider other)
    {
        DamageableObject objCanBeHit = other.gameObject.GetComponent <DamageableObject>();

        if (objCanBeHit != null)
        {
            DealDamage(objCanBeHit);
        }
    }
    void Awake()
    {
        damageablePlayer = GetComponent<DamageableObject>();

        if (!playerRB)
            playerRB = GetComponent<Rigidbody>();

        playerRB.freezeRotation = true;
    }
    private void OnCollisionEnter(Collision otherObj)
    {
        DamageableObject obj = otherObj.gameObject.GetComponent <DamageableObject>();

        if (obj != null)
        {
            DoImpact(obj);
        }
    }
Esempio n. 9
0
    private void OnTriggerEnter2D(Collider2D collider)
    {
        DamageableObject unit = collider.GetComponent <DamageableObject>();

        if (unit && unit.gameObject != parent)
        {
            unit.ReceiveDamage(_player.rangeAttackDamage);
            Destroy(gameObject);
        }
    }
Esempio n. 10
0
    // Damage player on a collision
    private void OnCollisionEnter(Collision collision)
    {
        GameObject       other = collision.gameObject;
        DamageableObject dobj  = other.GetComponent <DamageableObject>();

        if (other.tag == "Player" && currentCooldown <= 0)
        {
            dobj.damage(damageDone);
            currentCooldown = damageCooldown;
        }
    }
Esempio n. 11
0
    public void ActionClick(DamageableObject target, Vector3 point, Player comander)
    {
        if(curPawn !=null){
            curPawn.ActionClick(target, point, comander);

        }
        if(curBuilding !=null){
            curBuilding.ActionClick(target, point, comander);

        }
    }
Esempio n. 12
0
    // Giving damage to object if it`s have
    // DamageableObject component
    private void OnTriggerEnter2D(Collider2D col)
    {
        DamageableObject DamageObj = col.GetComponent <DamageableObject>();

        if (DamageObj != null && !_isAlreadyDamaged)
        {
            _isAlreadyDamaged = true;
            DamageObj.Damage(_damage);
            OnDeath();
        }
    }
Esempio n. 13
0
    /// <summary>
    /// Sends Damage from one DamageableObject to another DamageableObject
    /// </summary>
    /// <param name="damageSender">DamageableObject that is sending the damage</param>
    /// <param name="damageTo">DamageableObject that is receiving the damage</param>
    /// <param name="damageType">The type of damage that is being taken</param>
    /// <param name="damageDone">The amount of damage that is being sent</param>
    /// <param name="bIsStun">Is this damage going to stun the receiver</param>
    public void SendDamage(GameObject damageSender, DamageableObject damageTo, attribute damageType, float damageDone, bool bIsStun)
    {
        // Checks whether we're strong, neutral or weak against the attack's attribute.

        /* If we're stronger. Eg: We're Holy (0) and the attack is Demonic (1), or we're Natural (2) and 
        the attack is Holy (0). */
        if (damageTo.MyAttribute - damageType == -1 || damageTo.MyAttribute - damageType == 2)
        {
            // Halve damage.
            damageDone = damageDone / 2;
        }

        // If we're weaker.
        else if (damageTo.MyAttribute - damageType == 1 || damageTo.MyAttribute - damageType == -2)
        {
            // Double damage.
            damageDone = damageDone * 2;
        }

        // If we're the same.
        else
        {

        }

        damageTo.Health -= damageDone;

        if(damageTo.gameObject.tag != "Player")
        { 
            Rigidbody2D body = damageTo.gameObject.GetComponent<Rigidbody2D>();
            if(body)
            {
                if (damageSender.transform.position.x < damageTo.gameObject.transform.position.x)
                {
                    body.AddForce((Vector2.up + Vector2.right) * 250.0f);
                }
                else
                {
                    body.AddForce((Vector2.up - Vector2.right) * 250.0f);
                }
            }
        }

        if (bIsStun)
        {
            damageTo.bIsStunned = true;
        }

        if (!damageTo.bIsDamaged)
        {
            StartCoroutine(damageTo.CODamageCooldown());
        }
    }
Esempio n. 14
0
    // If projectile hits
    private void OnCollisionEnter(Collision collision)
    {
        GameObject       other = collision.gameObject;
        DamageableObject dobj  = other.GetComponent <DamageableObject>();

        // Check for damaging target
        if (dobj)
        {
            dobj.damage(damage);
        }

        Destroy(gameObject);
    }
Esempio n. 15
0
 public void ActionClick(DamageableObject target, Vector3 point, Player comander)
 {
     if(comander!=owner){
         return;
     }
     if(target!=null){
         Pawn targetPawn = target.GetComponent<Pawn>();
         if(targetPawn!=null&&targetPawn.team == team){
             FollowTarget(target);
         }else{
             AttackTarget(target);
         }
     }
 }
    private void HitNearbyObjects()
    {
        Collider[] colliders = Physics.OverlapSphere(this.transform.position, explosionRadius);

        Debug.Log("weapon impact hit " + colliders + " objects");

        for (int i = 0; i < colliders.Length; i++)
        {
            DamageableObject obj = colliders[i].gameObject.GetComponent <DamageableObject>();

            if (obj != null)
            {
                obj.ApplyHit(damage, explosionForce, this.transform.position, explosionRadius);
            }
        }
    }
Esempio n. 17
0
    //Deal damage to every enemy that was inside the attack hitbox when it was enabled
    void DealDamage(DamageableObject other)
    {
        //Determine damage dealt for the attack
        float attackDamage = Random.Range(damageMin, damageMax + 1);

        //Determine if the attack was a critical hit
        //If so, double the damage dealt
        if (Random.Range(0, 1.0f) <= critChance)
        {
            attackDamage = attackDamage * 2;
        }

        //JPS: Apply calculations for enchantments, such as additional crit chance, freezing chance, etc.

        other.TakeDamage(attackDamage);
    }
Esempio n. 18
0
    /// <summary>
    /// Spreads fire to neighbors.
    /// </summary>
    protected virtual void spreadFire()
    {
        Collider c = GetComponent <Collider>();

        Collider[] colliding = Physics.OverlapSphere(c.transform.position, 5);
        foreach (Collider hit in colliding)
        {
            DamageableObject b = hit.GetComponent <DamageableObject> ();

            if (b != null && !b.fire)
            {
                if (Random.value < .1f)
                {
                    b.setFire();
                }
            }
        }
    }
Esempio n. 19
0
    void Explode()
    {
        if (hasExploded)
        {
            return;
        }
        hasExploded = true;
        if (GameManager.S.inGame)
        {
            SoundManager.instance.Play("Explosion");
        }
        foreach (var bullet in trappedBullets)
        {
            if (bullet != null)
            {
                bullet.gameObject.layer = LayerMask.NameToLayer("Default");
            }
        }

        //Remove the hitboxes and sprite
        Destroy(inner);
        Destroy(outer);
        GetComponent <SpriteRenderer>().enabled = false;

        //Stop the inner particle system and immediately destroy the outer particle system
        innerParticleSystem.Stop();
        Destroy(outerParticleSystem.gameObject);

        //Play the explosion particle system
        explosion.Play();
        Collider[] hitTargets = Physics.OverlapSphere(transform.position, explosionRadius);
        foreach (Collider target in hitTargets)
        {
            //JPS: Bug, if a protag ship gets hit, it won't have a PlayerShip component
            if (target.gameObject.tag == "Player" || target.gameObject.tag == "ProtagShip")
            {
                DamageableObject shipHit = target.GetComponentInParent <DamageableObject>();
                shipHit.TakeDamage(explosionDamage);
            }
        }

        //Clean up
        Destroy(gameObject, 5f);
    }
Esempio n. 20
0
    private void Update()
    {
        transform.position += (transform.forward * Time.deltaTime * moveSpeed);

        RaycastHit hitInfo;

        if (Physics.Raycast(transform.position, transform.forward, out hitInfo, moveSpeed * Time.deltaTime * 2f))
        {
            DamageableObject dmg = hitInfo.collider.gameObject.GetComponent <DamageableObject>();
            if (dmg != null)
            {
                if (dmg.IsVRPlayer != isVRPlayer)
                {
                    dmg.GetHit(this);
                    Destroy(this.gameObject);
                }
            }
        }
    }
Esempio n. 21
0
    protected virtual bool CheckCollision(Vector3 direction, float distance)
    {
        Physics.Raycast(transform.position, direction.normalized, out hit, distance + colliderRadius, allowedLayers);
        bool IHit = hit.collider == null ? true : false;

        if (!IHit)
        {
            DamageableObject hitTarget = hit.collider.GetComponent <DamageableObject>();
            if (hitTarget != null)
            {
                hitTarget.TakeDamage(1);
                if (health <= 5)
                {
                    TakeDamage(1000);
                }
                TakeDamage(1);
            }
        }

        return(IHit);
    }
Esempio n. 22
0
    protected virtual void KillProjectile()
    {
        DamageableObject objectHiit = hit.collider.gameObject.GetComponent <DamageableObject>();

        if (objectHiit != null)
        {
            objectHiit.TakeDamage(Damage * damageMultiplier);
            if (playerUse)
            {
                ObjectPool.Instance.AddToList(gameObject);
            }
            else
            {
                Destroy(gameObject);
            }
        }
        else
        {
            Debug.Log("nothing found");
        }

        GameVariables.Instance.RemoveProjectile(projectileTransform.gameObject);
    }
Esempio n. 23
0
    //Damage any player or protag ship that is within the explosion
    void DamageTarget(Collider other)
    {
        if (other.tag == "Player")
        {
            Ship shipHit = other.gameObject.GetComponentInParent <Ship>();
            //Do damage to the player hit
            float     multiplier      = 1f;
            M*******t masochistPlayer = GameManager.S.players[(int)owningPlayer].character as M*******t;
            if (masochistPlayer != null)
            {
                multiplier = masochistPlayer.masochistShip.damageMultiplier;
            }
            damageDealt = CalculateDamageDealt(other.transform) * multiplier;
            shipHit.TakeDamage(damageDealt);
            //print("Damage Dealt: " + damageDealt);

            GameObject explosion = Instantiate(explosionPrefab, other.gameObject.transform.position, new Quaternion()) as GameObject;
            Destroy(explosion, 5f);
        }
        else if (other.tag == "ProtagShip")
        {
            DamageableObject otherShip       = other.gameObject.GetComponentInParent <DamageableObject>();
            M*******t        masochistPlayer = GameManager.S.players[(int)owningPlayer].character as M*******t;
            if (masochistPlayer != null)
            {
                damageDealt = CalculateDamageDealt(other.transform) * masochistPlayer.masochistShip.damageMultiplier;
            }
            else
            {
                damageDealt = CalculateDamageDealt(other.transform);
            }
            otherShip.TakeDamage(damageDealt);

            GameObject explosion = Instantiate(explosionPrefab, other.gameObject.transform.position, new Quaternion()) as GameObject;
            Destroy(explosion, 5f);
        }
    }
Esempio n. 24
0
    // Update is called once per frame
    void Update()
    {
        if (Input.GetButtonDown("Fire1") && Time.time > nextFire)
        {
            nextFire = Time.time + fireRate;
            StartCoroutine(shotEffect());

            Vector3    rayOrigin = fpsCam.ViewportToWorldPoint(new Vector3(0.5f, 0.5f, 0));
            RaycastHit hit;
            laserLine.SetPosition(0, gunEnd.position);

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

                if (target != null)
                {
                    target.damage(gunDamage);
                    if (hit.rigidbody != null)
                    {
                        hit.rigidbody.AddForce(-hit.normal * hitForce);
                    }
                }
            }
            else
            {
                laserLine.SetPosition(1, gunEnd.position + fpsCam.transform.forward * weaponRange);
            }
        }

        if (laserLine.enabled)
        {
            laserLine.SetPosition(0, gunEnd.position);
        }
    }
Esempio n. 25
0
    public void Shoot(Camera playerCam)
    {
        if (Time.time > nextFire)
        {
            nextFire = Time.time + fireRate[level - 1] / 60.0f;

            muzzleFlash.Play();

            Vector3    rayOrigin = playerCam.ViewportToWorldPoint(new Vector3(0.5f, 0.5f, 0));
            RaycastHit hit;

            if (Physics.Raycast(rayOrigin, GetShotDirection(playerCam.transform), out hit, range[level - 1]))
            {
                DamageableObject target = hit.collider.GetComponent <DamageableObject>();

                if (target != null)
                {
                    if (target.gameObject.tag != "player" || GameState.game_level == 4)
                    {
                        target.damage(damage[level - 1]);
                        if (hit.rigidbody != null)
                        {
                            hit.rigidbody.AddForce(-hit.normal * impactForce);
                        }
                    }
                }

                Instantiate(impactFx, target.transform);
            }
            else
            {
                // spawn particle effect at end of range
                Instantiate(impactFx, playerCam.transform.position + (playerCam.transform.forward * range[level - 1]), Quaternion.identity);
            }
        }
    }
Esempio n. 26
0
    public void drawSkelMounted(DamageableObject owner, int i, Vector2 scale)
    {
        Vector2 ownerpos = owner.mountedTo.Position;
        ownerpos.x -= boundsPosOffset.x * scale.x;
        ownerpos.y -= boundsPosOffset.y * scale.y;

        Matrix4x4 tr = owner.mountedTo.item.animList[0].skelMatrix(owner.mountedTo,owner.mountedTo.Position, owner.mountedTo.item.scale, owner.mountLoc);

        //tr = owner.mountedTo.skeleton[owner.mountLoc].worldTr;
        tr *= Matrix4x4.TRS(Vector3.zero, Quaternion.identity, scale / owner.mountedTo.item.Size);
        float rotOffset = owner.mountedTo.skeleton[owner.mountLoc].mountPoint[0].z;

        Quaternion rot;

        if (owner.flipped)
            rot = Quaternion.AngleAxis(-owner.skeleton[i].rotation, Vector3.forward);
        else
            rot = Quaternion.AngleAxis(owner.skeleton[i].rotation, Vector3.forward);

        tr *= owner.mountedTo.skeleton[owner.mountLoc].mountMatrix[0];

        tr *= Matrix4x4.TRS(new Vector3(0.5f, 0.5f, 0), Quaternion.AngleAxis(owner.rotation+rotOffset, Vector3.forward), Vector3.one);
        tr *= Matrix4x4.TRS(new Vector3(-0.5f, -0.5f, 0), Quaternion.identity, Vector3.one);
        tr *= owner.skeleton[i].tr;
        tr *= Matrix4x4.TRS(owner.skeleton[i].rotationPoint, rot, Vector3.one);
        tr *= Matrix4x4.TRS(-owner.skeleton[i].rotationPoint, Quaternion.identity, Vector3.one);

        if (owner.flipped)
            Graphics.DrawMesh(meshsFlipped[i], tr, OmniAtlas.texture, 0);
        else
            Graphics.DrawMesh(meshs[i], tr, OmniAtlas.texture, 0);
    }
Esempio n. 27
0
    public void drawSkelMountedProj(DamageableObject p,int i,Vector2 scale)
    {
        Matrix4x4 tr;
        Quaternion rot;

        Vector2 pos = new Vector2(p.mountedTo.Position.x + p.mountPos.x, p.mountedTo.Position.y + p.mountPos.y);
        tr = Matrix4x4.TRS(p.mountedTo.Position, Quaternion.identity, p.mountedTo.item.scale);

        tr *= Matrix4x4.TRS(new Vector3(0.5f, 0.5f, 0), Quaternion.AngleAxis(p.mountedTo.rotation, Vector3.forward), Vector3.one);
        tr *= Matrix4x4.TRS(new Vector3(-0.5f, -0.5f, 0), Quaternion.identity, Vector3.one);
        rot = Quaternion.AngleAxis(p.mountedTo.skeleton[p.mountLoc].rotation, Vector3.forward);
        Quaternion rot2 = Quaternion.AngleAxis(RotationOffset - 90, new Vector3(0, 0, 1));
        if (p.mountedTo.flipped)
            rot = Quaternion.AngleAxis(-p.mountedTo.skeleton[p.mountLoc].rotation, Vector3.forward);
        else
            rot = Quaternion.AngleAxis(p.mountedTo.skeleton[p.mountLoc].rotation, Vector3.forward);

        tr *= p.mountedTo.skeleton[p.mountLoc].tr;
        tr *= Matrix4x4.TRS(p.mountedTo.skeleton[p.mountLoc].rotationPoint, rot, Vector3.one);
        tr *= Matrix4x4.TRS(-p.mountedTo.skeleton[p.mountLoc].rotationPoint, Quaternion.identity, Vector3.one);
        if (!p.flipped)
            tr *= Matrix4x4.TRS(p.mountPos / p.mountedTo.item.Size, Quaternion.identity, Vector3.one);

        else
            tr *= Matrix4x4.TRS(p.mountPosFlipped / p.mountedTo.item.Size, Quaternion.identity, Vector3.one);

        Vector3 sc = new Vector3(scale.x / (p.mountedTo.skeleton[p.mountLoc].bounds.width * p.mountedTo.item.Size), scale.y / (p.mountedTo.skeleton[p.mountLoc].bounds.height * p.mountedTo.item.Size), 0);
        tr *= Matrix4x4.TRS(Vector3.zero, Quaternion.identity, scale / p.mountedTo.item.Size);

        tr *= Matrix4x4.TRS(new Vector3(-p.item.animList[0].boundsList[0].x, -p.item.animList[0].boundsList[0].y, 0), Quaternion.identity, Vector3.one);
        if (!p.flipped)
            tr *= Matrix4x4.TRS(new Vector3(p.item.animList[0].boundsList[0].x, p.item.animList[0].boundsList[0].y, 0), Quaternion.AngleAxis(p.mountRot, Vector3.forward), Vector3.one);
        else
            tr *= Matrix4x4.TRS(new Vector3(p.item.animList[0].boundsList[0].x, p.item.animList[0].boundsList[0].y, 0), Quaternion.AngleAxis(90 - p.mountRot, Vector3.forward), Vector3.one);
        tr *= Matrix4x4.TRS(new Vector3(-p.item.animList[0].boundsList[0].x, -p.item.animList[0].boundsList[0].y, 0), Quaternion.identity, Vector3.one);

        Graphics.DrawMesh(meshs[i], tr, OmniAtlas.texture, 0);
    }
Esempio n. 28
0
 public void RegisterEnemy(DamageableObject enemy)
 {
     enemies.Add(enemy);
 }
Esempio n. 29
0
 public void FollowTarget(DamageableObject  target)
 {
     movementTarget= target.transform;
     state=PawnState.Follow;
 }
Esempio n. 30
0
    // Perform raycast shoot
    public void Shoot(Camera playerCam)
    {
        // If able to fire
        if (Time.time > nextFire && !switching)
        {
            // Play fire effects
            nextFire = Time.time + (1 / fireRate[level - 1]);
            Recoil();
            if (gameObject.activeSelf)
            {
                StartCoroutine(shotEffect());
            }

            Vector3    rayOrigin = playerCam.ViewportToWorldPoint(new Vector3(0.5f, 0.5f, 0));
            RaycastHit hit;

            // Perform raycast
            if (Physics.Raycast(rayOrigin, playerCam.transform.forward, out hit, range[level - 1], Physics.DefaultRaycastLayers, QueryTriggerInteraction.Ignore))
            {
                DamageableObject target = hit.collider.GetComponent <DamageableObject>();

                // If hit object can be damaged
                if (target != null)
                {
                    // Check for friendly fire
                    if (target.gameObject.tag != "Player" || GameState.game_level == 4)
                    {
                        // Damage object and check if that killed it
                        bool kill = target.damage(damage[level - 1]);
                        if (kill)
                        {
                            // Provide money if shot got a kill
                            if (transform.parent.gameObject.GetComponent <WeaponManager>().playerNumber == 1)
                            {
                                GameState.player_one.money += 6;
                                GameState.player_two.money += 4;
                            }
                            else
                            {
                                GameState.player_two.money += 6;
                                GameState.player_one.money += 4;
                            }
                        }
                        // Knock back if hit object has physics
                        if (hit.rigidbody != null)
                        {
                            hit.rigidbody.AddForce(-hit.normal * impactForce);
                        }
                    }
                }

                // Create impact effect
                Instantiate(impactFx, hit.point, Quaternion.identity);
            }
            else
            {
                // Spawn scatter particle effect at end of range
                Instantiate(fizzleFx, playerCam.transform.position + (playerCam.transform.forward * range[level - 1]), Quaternion.identity);
            }
        }
    }
 private void DoImpact(DamageableObject hitObject)
 {
     HitNearbyObjects();
     Destroy(gameObject);
 }