Inheritance: MonoBehaviour
Beispiel #1
0
    protected virtual void ComponentSetup()
    {
        moveScript = GetComponent <MovementInterface> ();
        hpScript   = GetComponent <HPScript> ();
        if (hpScript == null)
        {
            hpScript = gameObject.AddComponent <HPScript> ();
        }
        hpScript.MaxHP  = maxHP;
        hpScript.Death += OnDeath;

        onCollisionDamageScript = gameObject.GetComponent <DamageOnCollision> ();
        if (onCollisionDamageScript == null)
        {
            onCollisionDamageScript = gameObject.AddComponent <DamageOnCollision> ();
        }
        onCollisionDamageScript.Damage  = onCollisionDamage;
        onCollisionDamageScript.TagList = onCollisionDamageTags;
        visionScript = GetComponent <EnemyVision> ();
        if (visionScript == null)
        {
            visionScript = gameObject.AddComponent <EnemyVision> ();
        }
        visionScript.AggroDistance   = aggroDistance;
        visionScript.AvatarDetected += OnAvatarDetected;
        visionScript.LostVision     += OnLostVision;
        visionScript.SeeingAvatar   += OnSeeingAvatar;
    }
Beispiel #2
0
    private void LaunchBullet(Muzzle muzzle, GameObject origin, Collider2D ignore = null)
    {
        Vector2 worldPos  = transform.TransformPoint(muzzle.pos);
        Vector2 direction = Rotate(transform.up, muzzle.angle);

        GameObject bullet = Instantiate(def.bulletPrefab, worldPos, Quaternion.FromToRotation(transform.up, direction) * transform.rotation);


        DamageOnCollision damageOnCollision = bullet.GetComponent <DamageOnCollision>();

        damageOnCollision.origin = origin;
        damageOnCollision.IgnoreCollisionWithOrigin = ignore != null;
    }
Beispiel #3
0
    internal void CreateProjectile(Vector2 ShootDir)
    {
        //  spawns object and sets parent
        GameObject        spawnObject = Instantiate(projectile);
        DamageOnCollision damage      = spawnObject.GetComponent <DamageOnCollision>();

        if (damage != null)
        {
            damage.ownerTag = tag;
        }

        spawnObject.GetComponent <Knockback>().ownerTag = tag;
        //  sets transform of spawned object, user direction is used to place it on one of the entitys sides
        spawnObject.transform.position = (Vector2)gameObject.transform.position + ShootDir;

        spawnObject.GetComponent <InputController>().move = ShootDir;

        //  gets the angle from the look direction
        float angle = Mathf.Atan2(ShootDir.y, ShootDir.x) * Mathf.Rad2Deg;

        //  rotates object to face the new angle
        spawnObject.transform.rotation = Quaternion.AngleAxis(angle, Vector3.forward);
    }