예제 #1
0
    void DisableObstacle(float duration)
    {
        //disable any behaviours that aren't obstacle behaviours
        MonoBehaviour[] behaviours = GetComponentsInChildren <MonoBehaviour>();
        foreach (MonoBehaviour b in behaviours)
        {
            if (b.GetType() != typeof(PoolableObstacle))
            {
                b.enabled = false;
            }
        }
        //disable any animators that may exist
        Animator anim;

        if (anim = GetComponent <Animator>())
        {
            anim.enabled = false;
        }
        //remove any physics materials
        savedPhysMats = new List <PhysicsMaterial2D>();
        Collider2D[] colliders = GetComponents <Collider2D>();
        foreach (Collider2D c in colliders)
        {
            savedPhysMats.Add(c.sharedMaterial);
            c.sharedMaterial = null;
        }
        //reset layer to default
        savedLayer       = gameObject.layer;
        gameObject.layer = 0;
        StartCoroutine(Timers.Countdown(duration, ReenableObstacle));
    }
예제 #2
0
 void sprayClusters(Transform actingLoc, Transform actedUponLoc)
 {
     if (lastSprayLocs == null)
     {
         lastSprayLocs = new List <Transform>();
     }
     if (!lastSprayLocs.Contains(actingLoc))
     {
         canSpray = true;
     }
     lastSprayLocs.Add(actingLoc);
     //canSpray puts a global cap on how fast this can fire
     if (canSpray && actingLoc.gameObject.layer != LayerMask.NameToLayer("Ground"))
     {
         //print("Spraying clusters from " + location + " at " + location.position);
         Vector2 dir = Vector2.up;
         if (actedUponLoc != null)
         {
             dir = (actingLoc.position - actedUponLoc.position).normalized;
         }
         for (int i = 0; i < fireAmount; i++)
         {
             StartCoroutine(Timers.Countdown <Transform, Vector2>(
                                UnityEngine.Random.Range(0f, 0.1f), shootCluster, actingLoc, dir));
         }
         canSpray = false;
         Invoke("enableSpray", cooldown);
     }
 }
    void speedBoost(Transform t1, Transform t2)
    {
        GameActor actor = t1.GetComponent <GameActor>();

        actor.maxSpeed += effectSize / 10;
        StartCoroutine(Timers.Countdown <Transform>(cooldown / 2, removeSpeedBoost, t1));
    }
 public void init(System.Action <Transform> action, float period, float activateChance)
 {
     this.action         = action;
     this.period         = period;
     this.activateChance = activateChance;
     StartCoroutine(Timers.Countdown <Transform>(period, activate, transform));
 }
    // Update is called once per frame
    void Update()
    {
        fireInterval = 1 / fireSpeed;

        Vector2 mousePos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
        Vector2 myPos    = transform.position;
        float   angle    = signedAngle(transform.right, (mousePos - myPos).normalized);

        //print(angle);
        transform.Rotate(Vector3.forward, angle);

        /*
         * if(Mathf.Sign (transform.parent.localScale.x) < 0) {
         *      Vector3 right = transform.right;
         *      right.x = -right.x;
         *      transform.right = right;
         *      Quaternion rot = transform.rotation;
         *      rot.w = -rot.w;
         *      transform.rotation = rot;
         *      transform.Rotate(Vector3.forward,180);
         * }
         */

        if (Input.GetMouseButton(0) && canFire)
        {
            canFire = false;
            FireBullet(transform.right);
            StartCoroutine(Timers.Countdown(fireInterval, EnableFire));
        }

        //print(transform.right);
        Debug.DrawLine(transform.position, myPos + facingDir.normalized * 2, Color.red);
    }
예제 #6
0
 void OnEnable()
 {
     startPos   = transform.position;
     startTime  = Time.time;
     startColor = text.color;
     color      = startColor;
     StartCoroutine(Timers.Countdown(lifetime, Destroy));
 }
 void activate(Transform t1)
 {
     if (Random.value < activateChance)
     {
         action(t1);
     }
     StartCoroutine(Timers.Countdown <Transform>(period, activate, transform));
 }
예제 #8
0
 void doBuff(Transform applier, Transform target)
 {
     buffEffect(applier, target);
     if (buffDuration > 0)
     {
         StartCoroutine(Timers.Countdown <Transform, Transform>(buffDuration, undoBuff, applier, target));
     }
 }
예제 #9
0
 public void StartSpawning()
 {
     //Debug.Log(name + " starting spawning");
     StartCoroutine(Timers.Countdown <List <GameObject>, float>(1 / goodPerSec, Spawn, colourBalls, 1 / goodPerSec));
     StartCoroutine(Timers.Countdown <List <GameObject>, float>(1 / badPerSec, Spawn, badBalls, 1 / badPerSec));
     StartCoroutine(Timers.Countdown <List <GameObject>, float>(1 / bonusPerSec, Spawn, bonusBalls, 1 / bonusPerSec));
     spawning = true;
 }
    protected void Dash(float dashPower)
    {
        dashing        = true;
        this.dashPower = dashPower;

        savedGravity             = rigidbody2D.gravityScale;
        rigidbody2D.gravityScale = 0;
        StartCoroutine(Timers.Countdown(0.05f, EndDash));
    }
예제 #11
0
 void doBuff(Action <Transform, Transform> buffEffect, Action <Transform, Transform> undoBuff,
             Transform applier, Transform target, float duration)
 {
     buffEffect(applier, target);
     if (duration > 0)
     {
         StartCoroutine(Timers.Countdown <Transform, Transform>(duration, undoBuff, applier, target));
     }
 }
 public void triggerActive(Transform player)
 {
     if (canActivate)
     {
         canActivate = false;
         activeFunc(player);
         StartCoroutine(Timers.Countdown(cooldown, enableFire));
     }
 }
예제 #13
0
 void OnCollisionEnter2D(Collision2D col)
 {
     if (onHit != null && canActivate && (triggerLayers.value & 1 << col.gameObject.layer) != 0)
     {
         print("Firing onHit from " + transform + " at " + transform.position);
         onHit(transform, col.transform);
         canActivate = false;
         StartCoroutine(Timers.Countdown(cooldown, enableActivate));
     }
 }
예제 #14
0
 public void GetShocked(float duration, Material shockedMat)
 {
     if (!FlagsHelper.IsSet <BallStatus>(status, BallStatus.SHOCKED))
     {
         GetComponent <Renderer>().sharedMaterial = shockedMat;
         AddStatus(BallStatus.SHOCKED, shockedMat);
         AttachedBall.AddStatusAllAttachedBalls(transform, BallStatus.SHOCKED, shockedMat);
         StartCoroutine(Timers.Countdown(duration, () => RemoveStatus(BallStatus.SHOCKED, shockedMat)));
     }
 }
예제 #15
0
 public void GetInfected(Material infectionMat, float spreadInterval)
 {
     GetComponent <SpriteRenderer>().sharedMaterial = infectionMat;
     AddStatus(BallStatus.INFECTED, infectionMat);
     SetPointValue(0);
     ScoreCalculator.Instance.SetScorePrediction();
     if (transform.parent != null)
     {
         StartCoroutine(Timers.Countdown <Material, float>(spreadInterval, SpreadInfection, infectionMat, spreadInterval));
     }
 }
예제 #16
0
 void EnableObstacle()
 {
     if (disableTime + offTime < Time.time)
     {
         SetFiring(true);
     }
     else
     {
         StartCoroutine(Timers.Countdown <bool>(disableTime + offTime - Time.time, SetFiring, true));
     }
 }
예제 #17
0
    override public void activeEffect(Transform player)
    {
        if (channeler == null)
        {
            channeler = player.FindChild("channeler");
        }


        for (int i = 0; i < fireAmount; i++)
        {
            StartCoroutine(Timers.Countdown <Transform>(UnityEngine.Random.Range(0f, 0.1f), shootCluster, player));
        }
    }
예제 #18
0
    void Lick(Vector2 position)
    {
        isLicking  = true;
        onCooldown = true;
        StartCoroutine(Timers.Countdown(cooldown, ResetCooldown));
        lr.enabled = true;
        sr.enabled = true;
        Vector2 mouthPos     = mouth.position;
        Vector2 relativeDest = Vector2.ClampMagnitude(position - mouthPos, maxDist);

        destination       = mouthPos + relativeDest;
        distanceTravelled = 0;
    }
예제 #19
0
    void FireProjectile(Vector3 firingDir, float speed)
    {
        GameObject proj = projPool.GetPooled();

        proj.SetActive(true);
        Physics2D.IgnoreCollision(collider2D, proj.collider2D);
        proj.transform.position   = firingPos.position;
        proj.transform.rotation   = Quaternion.FromToRotation(Vector3.right, firingDir);
        proj.rigidbody2D.velocity = firingDir * speed;

        canFire = false;
        StartCoroutine(Timers.Countdown(cooldown, EnableFire));
    }
예제 #20
0
 IEnumerator RestockTimer()
 {
     while (true)
     {
         stockChangeTimer -= 1;
         if (stockChangeTimer <= 0)
         {
             stockChangeTimer = maxStockTimer;
             GenerateStock();
         }
         UIManager.Instance.SetStoreTimer(Timers.Countdown(stockChangeTimer));
         yield return(new WaitForSeconds(1f));
     }
 }
예제 #21
0
 void Fire()
 {
     if (canFire)
     {
         anim.SetTrigger("fire");
         GameObject proj = projPool.GetPooled();
         Physics2D.IgnoreCollision(proj.collider2D, collider2D);
         proj.SetActive(true);
         proj.transform.position   = barrel.position;
         proj.transform.rotation   = barrel.rotation;
         proj.rigidbody2D.velocity = (barrel.position - transform.position).normalized * projVelocity;
         StartCoroutine(Timers.Countdown(reloadingTime, Reload));
         canFire = false;
     }
 }
예제 #22
0
 public void GetFrozen(float duration, Material frozenMat)
 {
     if (!FlagsHelper.IsSet <BallStatus>(status, BallStatus.FROZEN))
     {
         GetComponent <Renderer>().sharedMaterial = frozenMat;
         AddStatus(BallStatus.FROZEN, frozenMat);
         GetComponent <Rigidbody2D>().velocity    = Vector2.zero;
         GetComponent <Rigidbody2D>().isKinematic = true;
         AttachedBall.AddStatusAllAttachedBalls(transform, BallStatus.FROZEN, frozenMat);
         StartCoroutine(Timers.Countdown(duration, () => {
             RemoveStatus(BallStatus.FROZEN, frozenMat);
             GetComponent <Rigidbody2D>().isKinematic = false;
         }));
     }
 }
예제 #23
0
    GameObject getBullet(Transform spawnLoc)
    {
        GameObject bullet = clusterPool.getPooled();

        bullet.SetActive(true);
        bullet.transform.position = spawnLoc.position;

        PoolableProjectile proj = bullet.GetComponent <PoolableProjectile>();

        proj.IgnoreCollider(PlayerController.GlobalPlayerInstance.collider2D);
        proj.SetOnCollision(onCollision, onCollisionTargets);

        proj.collider2D.enabled = false;
        StartCoroutine(Timers.Countdown <GameObject>(0.1f, enableBulletCollision, bullet));

        return(bullet);
    }
예제 #24
0
    void SetFiring(bool firing)
    {
        if (firing)
        {
            isFiring = true;

            for (int i = 0; i < laserLength; i++)
            {
                PoolableSprite beam = beamPool.GetPooled().GetComponent <PoolableSprite>();

                if (verticalFire)
                {
                    beam.transform.position = firingPosition.position + new Vector3(0, i * laserPieceLength);
                }
                else
                {
                    beam.transform.position = firingPosition.position + new Vector3(i * laserPieceLength, 0);
                }

                beam.gameObject.SetActive(true);
                beam.SendMessage("SetTurret", transform);
                beams.Add(beam);
            }
            end = endPool.GetPooled().GetComponent <PoolableSprite>();
            if (verticalFire)
            {
                end.transform.position = firingPosition.position + new Vector3(0, (laserLength) * laserPieceLength);
            }
            else
            {
                end.transform.position = firingPosition.position + new Vector3((laserLength) * laserPieceLength, 0);
            }

            end.gameObject.SetActive(true);
            end.SendMessage("SetTurret", transform);
            StartCoroutine(Timers.Countdown <bool>(onTime, SetFiring, false));
        }
        else
        {
            isFiring = false;
            TurnOffBeams();
            StartCoroutine(Timers.Countdown <bool>(offTime, SetFiring, true));
        }
    }
예제 #25
0
    public static void AddStatusAllAttachedBallsTemp(Transform t, BallStatus newStatus, Material mat, float duration)
    {
        AttachedBall ab;

        if (ab = t.GetComponent <AttachedBall>())
        {
            //we make copies so the delegate we create keeps its own state
            //Material oldMat = t.GetComponent<SpriteRenderer>().sharedMaterial;
            //Transform trans = t;
            ab.AddStatus(newStatus, mat);
            ab.StartCoroutine(Timers.Countdown(duration, () => {
                ab.RemoveStatus(newStatus, mat);
            }));
        }
        foreach (Transform child in t)
        {
            AddStatusAllAttachedBallsTemp(child, newStatus, mat, duration);
        }
    }
예제 #26
0
    public void Spawn(List <GameObject> collection, float interval)
    {
        if (spawning)
        {
            GameObject ball = null;
            //Debug.Log ("Selecting ball");
            if (collection != null && collection.Count > 0)
            {
                ball = Util.GetRandomElement <GameObject>(collection);
            }

            if (ball != null)
            {
                //Debug.Log ("Spawning a " + ball.name);
                SpawnBall(ball);
            }
            //randomise the spawn a little bit
            float nextInterval = interval + Util.RandomSign() * Random.Range(0.1f, 0.2f) * interval;
            StartCoroutine(Timers.Countdown <List <GameObject>, float>(nextInterval, Spawn, collection, interval));
        }
    }
예제 #27
0
    public void GetGlooped(float duration, Material gloopMat)
    {
        if (!FlagsHelper.IsSet <BallStatus>(status, BallStatus.GLOOPED))
        {
            GetComponent <Renderer>().sharedMaterial = gloopMat;
            AddStatus(BallStatus.GLOOPED, gloopMat);
            //we make copies so the delegate we create keeps its own state

            /*
             * Material oldMat = GetComponent<SpriteRenderer>().sharedMaterial;
             * Transform trans = transform;
             * GetComponent<SpriteRenderer>().sharedMaterial = gloopMaterial;
             * StartCoroutine(Timers.Countdown(duration,() => {
             *      Debug.Log ("Resetting mat to " + oldMat.name + " " + oldMat.GetInstanceID());
             *      trans.GetComponent<SpriteRenderer>().sharedMaterial = oldMat;
             * }));
             */
            AttachedBall.AddStatusAllAttachedBalls(transform, BallStatus.GLOOPED, gloopMat);
            StartCoroutine(Timers.Countdown(duration, () => RemoveStatus(BallStatus.GLOOPED, gloopMat)));
        }
    }
예제 #28
0
파일: Swooper.cs 프로젝트: EternalGB/frogue
 void Update()
 {
     if (isSwooping)
     {
         nextPos.x = Mathf.Clamp(nextPos.x - swoopSpeed * Time.deltaTime, -startingX, startingX);
         nextPos.y = SimpleQuadratic(parabolicParam, nextPos.x);
         //Debug.Log ("Fly moving to " + (swoopDest + nextPos));
         rigidbody2D.MovePosition(swoopDest + nextPos);
         if (nextPos.x == -startingX)
         {
             anim.SetTrigger("wait");
         }
     }
     else if (!acquiringTarget)
     {
         target = Physics2D.OverlapCircle(transform.position, detectionRange, targets);
         if (target)
         {
             anim.SetTrigger("swoop");
             acquiringTarget = true;
             StartCoroutine(Timers.Countdown(armingTime, BeginSwoop));
         }
     }
 }
예제 #29
0
 public void Arm()
 {
     StartCoroutine(Timers.Countdown(lifeTime, Destroy));
 }
예제 #30
0
 public void Activate()
 {
     onCooldown = true;
     StartCoroutine(Timers.Countdown(cooldown, ResetCooldown));
     Action();
 }