コード例 #1
0
    public void MakeLittleBlueExplosion(Vector3 pos)
    {
        GameObject            exp = (GameObject)Instantiate(littleBlueExplosion, pos, Quaternion.identity);
        TimedObjectDestructor tod = exp.AddComponent <TimedObjectDestructor>();

        tod.DestroyNow(2);
    }
コード例 #2
0
    public GameObject MakeIntoRocket(GameObject rocket)
    {
        TimedObjectDestructor tod = rocket.AddComponent <TimedObjectDestructor>();

        tod.autoDestruct = false;
        tod.DestroyNow(10);         // rockets die out after 10 secodns.

        rocket.transform.parent = null;
        rocket.GetComponent <Collider>().enabled = true;
        // Create the rocket.


        rocket.GetComponent <Rigidbody>().isKinematic            = false; // Why is this true by default?!
        rocket.GetComponent <Rigidbody>().useGravity             = false;
        rocket.GetComponent <Rigidbody>().drag                   = 0.01f;
        rocket.GetComponent <Rigidbody>().angularDrag            = 0.01f;
        rocket.GetComponent <Rigidbody>().collisionDetectionMode = CollisionDetectionMode.ContinuousDynamic;


        NumberInfo ni = rocket.GetComponent <NumberInfo>();

        if (!ni.gameObject.GetComponent <DoesExplodeOnImpact>())
        {
            ni.gameObject.AddComponent <DoesExplodeOnImpact>();
        }
        //		// commented Debug.Log ("rocket created, value;"+rocket.GetComponent<NumberInfo>().fraction);
        return(rocket);
    }
コード例 #3
0
    void OnDestroy()
    {
        if (smokeTrail)
        {
            TimedObjectDestructor tod = smokeTrail.AddComponent <TimedObjectDestructor>();
        }
//		tod.DestroyNow(2.5f);
//		Destroy (smokeTrail);
    }
コード例 #4
0
    virtual public void CleanObjectOnCollect(GameObject obj)
    {
        TimedObjectDestructor tod = obj.GetComponent <TimedObjectDestructor>();        // Very awkward way to stop this from happening..

        if (tod)
        {
            tod.StopAllCoroutines();
            UnityEngine.Object.Destroy(tod);
        }
    }
    void Fire()
    {
        AudioManager.inst.PlayNumberFire(transform.position, 1);
//		AudioManager.inst.PlayPlungerSuck(transform.position,1,1
        Vector3    pos = firePos.position;
        GameObject num = NumberManager.inst.CreateNumber(number, pos, NumberShape.Cube);

        mynums.Add(num);
        EffectsManager.inst.CreateSmokePuffBig(pos + transform.right * 4, firePos.forward * 5 + Vector3.up, Random.Range(8, 15));
        num.transform.localScale = Vector3.one * scale;
        num.GetComponent <Rigidbody>().useGravity  = false;
        num.GetComponent <Rigidbody>().isKinematic = false;
        if (rotate)
        {
            num.AddComponent <Rotate>();
        }
        num.transform.parent = bucket.transform;
        num.GetComponent <Rigidbody>().drag        = 0;
        num.GetComponent <Rigidbody>().angularDrag = 0;
        if (numbersAreEnemyRockets)
        {
//			num.AddComponent<DestroyOnPlayerTouch>();
//			DestroyNumbersInFiringLine d= num.AddComponent<DestroyNumbersInFiringLine>();
//			d.line=this;


            NumberInfo ni = num.GetComponent <NumberInfo>();
//			NumberManager.inst.ApplySpikes(ni,true);
//			ni.pickupFlag=false;
//			ni.killPlayerOnContact=true;
            num.AddComponent <EnemyBrick>();
//			AttackPlayerWithLightning l = num.AddComponent<AttackPlayerWithLightning>();
//			l.range=50;
//			GameObject smokeTrail = (GameObject)Instantiate(EffectsManager.inst.smokeTrail,num.transform.position,Quaternion.identity); // add smoke trail
//			smokeTrail.name = "smokeTrail";
//			smokeTrail.transform.parent = num.transform;
//			num.GetComponent<NumberInfo>().doesExplodeOnImpact=true;
        }

        TimedObjectDestructor tod = num.AddComponent <TimedObjectDestructor>();

        tod.autoDestruct = false;
        tod.DestroyNow(timeout);

        // make cannon shake on each fire
        float jumpForce = 120;

        GetComponent <Rigidbody>().AddForce(new Vector3(Random.Range(-10, 10), Random.Range(30, 50), Random.Range(-10, 10)) * jumpForce);
        if (addToPlayerNumber)
        {
//			num.AddComponent<CombineOnPlayerTouch>();
            num.layer = 25;             // collide with player and numbers only.
        }
    }
コード例 #6
0
    public void Die()
    {
        if (stem)
        {
            stem.transform.parent = null;
            stem.AddComponent <Rigidbody>();
            TimedObjectDestructor tod = stem.AddComponent <TimedObjectDestructor>();
            stem.GetComponent <Rigidbody>().AddForce(Random.insideUnitSphere * 500f);
            tod.DestroyNow(Random.Range(5f, 10f));
        }
//		Debug.Log("I dieded.:"+name);
        Destroy(gameObject);
    }
 void Update()
 {
     lightningTimerFX -= Time.deltaTime;
     if (lightningTimerFX < 0)
     {
         lightningTimerFX = Random.Range(.5f, 1f);
         GameObject randomG = new GameObject();
         randomG.transform.position = transform.position + Random.insideUnitSphere * radius;
         TimedObjectDestructor tod = randomG.AddComponent <TimedObjectDestructor>();            // what is default seconds.. and why..ugh
         float randomDuration      = Random.Range(1.2f, 1.5f);
         SMW_GF.inst.CreateLightning(transform, randomG.transform, randomDuration);
     }
 }
コード例 #8
0
 void Start()
 {
     inst = this;
     foreach (Effect e in effects)
     {
         e.ps = (ParticleSystem)Instantiate(e.particleSystem).GetComponent <ParticleSystem> ();
         TimedObjectDestructor tod = e.ps.gameObject.GetComponent <TimedObjectDestructor> ();
         if (tod)
         {
             Destroy(tod);                  // awkward but these have TODs for when they're instantiated by other behaviors
         }
         effectsList.Add(e.name, e);
         e.ps.transform.position = Vector3.zero;
     }
 }
コード例 #9
0
    bool checkChildren = false;     // don't need to check until we've generated a few.
    GameObject GenerateSpikey()
    {
        checkChildren = true;
        GameObject spikey = (GameObject)Instantiate(spikeyPrefab, generatorT.position, Quaternion.identity);

        spikey.GetComponent <NumberInfo>().SetNumber(spikeyFraction);
        float throwForce = 5200f;

        spikey.GetComponent <Rigidbody>().AddForce(transform.forward * throwForce);
        spikey.transform.parent = transform;
        TimedObjectDestructor tod = spikey.AddComponent <TimedObjectDestructor>();

        tod.DestroyNow(20f);
        return(null);
    }
コード例 #10
0
    public void TempDebugSphere(Vector3 p, Color c)
    {
        float tempDebugInterval = 0.2f;

        if (Utils.IntervalElapsed(tempDebugInterval))
        {
            GameObject debugSphere = GameObject.CreatePrimitive(PrimitiveType.Sphere);
            debugSphere.transform.position   = p;
            debugSphere.transform.localScale = Vector3.one * .5f;
//			debugSphere.name = "Debug sphere";
            debugSphere.GetComponent <Renderer>().material.color = c;
            Destroy(debugSphere.GetComponent <Collider>());
            TimedObjectDestructor tod = debugSphere.AddComponent <TimedObjectDestructor>();
            tod.DestroyNow(tempDebugInterval);
        }
    }
コード例 #11
0
    void Die()
    {
        dead = true;
        transform.root.GetComponentInChildren <ResourceDrop>().DropResource();
        // commented Debug.Log("Dying now.");
        foreach (NumberInfo ni in myBlocks)
        {
            if (ni != null)
            {
                if (transform.root.GetComponentInChildren <LevelMonster_Shield>())
                {
                    Destroy(transform.root.GetComponentInChildren <LevelMonster_Shield>().gameObject);
                }

                ni.transform.parent = null;
                if (!ni.gameObject.GetComponent <Rigidbody>())
                {
                    ni.gameObject.AddComponent <Rigidbody>();
                    ni.GetComponent <Rigidbody>().mass = 4;
                    ni.GetComponent <Rigidbody>().drag = .2f;
                }
                ni.gameObject.GetComponent <Collider>().isTrigger = false;
                if (ni.GetComponent <Rigidbody>())
                {
                    ni.GetComponent <Rigidbody>().isKinematic = false;
                    ni.GetComponent <Rigidbody>().useGravity  = true;
                }
//				ni.pickupFlag = true; // todo: Make inventory recognize cube numbers as well.
                ni.gameObject.layer   = LayerMask.NameToLayer("Default");
                ni.greaterThanCombine = 0;
                ni.lessThanCombine    = 1;
//				if (ni.transform.transform.localScale.x > 3) // crit block scale is 4 and other block scale is 2.6

                PickUppableObject pip = ni.gameObject.AddComponent <PickUppableObject>();
                pip.heldScale = 1.5f;                 //2 / ni.transform.localScale.x;

//				}
//				pip.heldScale
//				rocketLauncher.gameObject.AddComponent<Rigidbody>();
                rocketLauncher.transform.parent = null;
                TimedObjectDestructor tod = rocketLauncher.gameObject.AddComponent <TimedObjectDestructor>();
            }
        }
        Destroy(transform.root.gameObject);
    }
コード例 #12
0
    void Fire()
    {
        if (!canFire)
        {
            return;
        }
        firecount += 1;
//		AudioManager.inst.PlayNumberFire(transform.position,1);
//		AudioManager.inst.PlayPlungerSuck(transform.position,1,false,.5f);
        Vector3    pos = firePos.position;
        GameObject num = (GameObject)Instantiate(bulletPrefab);

        num.transform.position = pos;

        EffectsManager.inst.CreateSmokePuffBig(pos + transform.right * 4, firePos.forward * 5 + Vector3.up, Random.Range(8, 15));
        num.transform.localScale = Vector3.one * scale;
//		if (rotate) num.AddComponent<Rotate>();
        Color c;

        num.layer = 25;         // collide with player and numbers only.
//		// commented Debug.Log ("number numerator % firecount: " + number.numerator + " % " + firecount + " = " + (number.numerator % firecount));
        if (firecount % number.numerator == 0)
        {
            c = Color.white;
        }
        else
        {
            c = Color.black;
            num.GetComponent <Collider>().isTrigger = true;
        }


        TimedObjectDestructor tod = num.AddComponent <TimedObjectDestructor>();

        tod.autoDestruct = false;
        tod.DestroyNow(timeout);

        // make cannon shake on each fire
        float jumpForce = 120;

//		rigidbody.AddForce(new Vector3(Random.Range(-10,10),Random.Range(30,50),Random.Range(-10,10))*jumpForce);
        StartCoroutine(AddToPoolAfterSeconds(interval / 2f, num, c));
    }
コード例 #13
0
    List <MeshRenderer> cachedMeshRenderers = new List <MeshRenderer>();   //This one is for fading out the Mesh Renderers used by the Ferr2D terrain tool

    void Awake()
    {
        CacheRenderers();
        destructor = GetComponent <TimedObjectDestructor>();
    }
コード例 #14
0
    void OnCollisionEnter(Collision hit)
    {
        Collider   other = hit.collider;
        NumberInfo ni    = other.GetComponent <NumberInfo>();

        if (!ni)
        {
            // hit the ground or something. Stick in the ground, become noninteractable (or can you still pick up?)
//			Debug.Log("hit;"+other.name);
            GetComponent <Rigidbody>().isKinematic = true;
            transform.parent = GetComponent <Collider>().transform;
            TimedObjectDestructor tod = gameObject.AddComponent <TimedObjectDestructor>();
            tod.DestroyNow(2);
        }
        else if (ni.myShape == NumberShape.Sphere)
        {
            // Divide the number.
            int       degreesToComplete = 360;
            float     radius            = 4f;
            float     scale             = radius / 3.2f / 3.2f;
            int       count             = Mathf.Abs(ni0.fraction.numerator);
            int       startingDegrees   = Mathf.FloorToInt(Player.inst.transform.rotation.eulerAngles.y + 90);
            Vector3[] circlePoints      = MathUtils.GetPointsOfACircle(degreesToComplete, radius, scale, count, startingDegrees); // why is there a 19 here?
            float     splashForce       = 340f;                                                                                   // after the arrow splits this number, how much force does each piece move away with?
            Fraction  result            = Fraction.Multiply(ni.fraction, ni0.fraction.GetReciprocal());
            for (int i = 0; i < circlePoints.Length; i++)
            {
                Vector3 pos = hit.contacts[0].point + circlePoints[i] + Vector3.up * 2;
                ni.SetNumber(result);
                ni.gameObject.AddComponent <BowSplitNumber>();
                ni.ForbidCombinationsForSeconds(5);                                                    // don't collide with nearby stuff right away.
                GameObject piece = (GameObject)Instantiate(ni.gameObject, pos, ni.transform.rotation); // NumberManager.inst.CreateNumber(result),pos,NumberShape.Sphere);
                Animal     an    = piece.GetComponent <Animal>();
                if (an)
                {
                    // in case we split a frog while it's tonguing.
                    if (an.target != null)
                    {
                        if (an.target.transform)
                        {
                            Destroy(an.target.transform.gameObject);
                        }
                    }
                    an.LoseTarget();
                }
//				ScaleUpAndStop sc = piece.AddComponent<ScaleUpAndStop>();
//				sc.stopScale = piece.transform.localScale;
//				piece.transform.localScale = Vector3.one * 0.4f;

//				piece.GetComponent<NumberInfo>().InitSinGrowAttributes();
                Vector3   dir = Vector3.Normalize(pos - other.transform.position) + Vector3.up;
                Rigidbody rb  = piece.GetComponent <Rigidbody>();
                if (!rb)
                {
                    rb = piece.AddComponent <Rigidbody>();
                    rb.freezeRotation = true;
                    rb.drag           = 1f;
                }
                rb.mass = Mathf.Max(10, rb.mass);
                rb.drag = Mathf.Max(.05f, rb.drag);
                rb.AddForce(dir * splashForce);
            }
            NumberManager.inst.DestroyOrPool(ni);
            Destroy(gameObject);
        }
    }