Beispiel #1
0
    // Use this for initialization
    void Start()
    {
        mColliders = GetComponents <Collider2D>();                  //Find colliders
        Debug.Assert(mColliders.Length > 0, "Collider(s) missing"); //Show error if not found

        mFakePhysics = GetComponent <FakePhysics>();                //Add required Fake physics in code
        Debug.Assert(mFakePhysics != null, "Needs FakePhysics");    //Check its added ok

        mExplosion = GetComponentInChildren <Explosion>();
        Debug.Assert(mExplosion != null, "No Explosion found in hierachy");

        foreach (var mCollider in mColliders) //Step through all the colliders
        {
            mCollider.isTrigger = true;       //Use code to turn collider to triggers
        }

        mSR = GetComponent <SpriteRenderer>();               //Get SpriteRenderer
        Debug.Assert(mSR != null, "SpriteRenderer missing"); //Show error if not found

        mRB2D = gameObject.AddComponent <Rigidbody2D>();     //Add RB2D in code
        Debug.Assert(mRB2D != null, "Needs Rigidbody2D");    //Check its added ok
        mRB2D.isKinematic = true;                            //Make it non physics in code, so triggers still work, but no forces act on it


        mAngle = Random.Range(-45.0f, 45.0f); //Set a random rotation rate

        if (RandomVelocity)                   //If IDE variable is set then give an initial random velocity
        {
            mFakePhysics.mVelocity = FakePhysics.RandomDirection() * Random.Range(1.0f, 5.0f);
        }
    }
Beispiel #2
0
    Rigidbody2D mRB2D;         //Cached Variable for quick access

    // Use this for initialization
    void Start()
    {
        mFakePhysics = GetComponent <FakePhysics>();                    //Add Fake Physics in code
        Debug.Assert(mFakePhysics != null, "Needs FakePhysics");        //Check its added ok

        mFakePhysics.MaxSpeed  = 10.0f;                                 //Set UFO Max Speed
        mFakePhysics.mVelocity = FakePhysics.RandomDirection() * Speed; //Set UFO Random direction

        mRB2D = gameObject.AddComponent <Rigidbody2D>();                //Add RB2D in code
        Debug.Assert(mRB2D != null, "Needs Rigidbody2D");               //Check its added ok
        mRB2D.isKinematic = true;                                       //Make it non physics in code, so triggers still work, but no forces act on it
    }
Beispiel #3
0
 //Make a random direction change every few seconds
 void UpdateDirection()
 {
     if (mTimeOut <= 0)
     {
         mFakePhysics.mVelocity = FakePhysics.RandomDirection() * Speed; //Get Random direction an scale with speed
         mTimeOut = Random.Range(1, 10);                                 //Set new random timeout
         Fire[] tFirePoint = GetComponentsInChildren <Fire>();
         foreach (var tFP in tFirePoint)
         {
             tFP.DoFire();
         }
     }
     else
     {
         mTimeOut -= Time.deltaTime; //subtract the time since last update
     }
 }