Example #1
0
    public void Die()
    {
        Vector3 pos = this.transform.position;

        pos.y -= 10;
        GameObject obj;

        //GameObject obj = Instantiate (fire, pos, Quaternion.identity) as GameObject;
        //if(size==1) obj.transform.localScale=new Vector3 (0.5f,0.5f,0.5f);
        if (size == 2)
        {
            //int ran=Random.Range(2,6);
            int ran = 3;
            pos.y += 20;
            for (int i = 0; i < ran; i++)
            {
                float angle = Mathf.PI * i / ran * 2, vx, vy, vz;
                pos.x += 10 * Mathf.Cos(angle);
                pos.z += 10 * Mathf.Sin(angle);
                obj    = Instantiate(stone, pos, Quaternion.identity) as GameObject;
                obj.transform.localScale = new Vector3(10f, 10f, 10f);
                vx = Mathf.Cos(angle) * 1800;
                vy = 1000;
                vz = Mathf.Sin(angle) * 1800;
                obj.rigidbody.AddRelativeForce(vx, vy, vz);
                volcanoStone s = obj.GetComponent <volcanoStone>();
                s.size = 1;
            }
        }
        Destroy(gameObject);
    }
Example #2
0
 // Update is called once per frame
 void Update()
 {
     deltaEruptTime += Time.deltaTime;
     if (deltaEruptTime > eruptCycleTime)
     {
         deltaEruptTime = 0f;
         //int n=Random.Range(10,15);
         int n = 4;
         for (int i = 0; i < n; i++)
         {
             float vx, vz, vl;
             //vx=Random.Range(0,500);
             //vz=Random.Range(1100,2200);
             vl = 1200;
             vx = Mathf.Cos(120 + 1.0f * i / n * 2 * Mathf.PI) * vl;
             vz = Mathf.Sin(120 + 1.0f * i / n * 2 * Mathf.PI) * vl;
             //if(Random.Range(0.0f,1.0f)<0.5f) vx=-vx;
             //if(Random.Range(0.0f,1.0f)<0.5f) vz=-vz;
             GameObject   obj = Instantiate(stone, new Vector3(554, 533, 390), Quaternion.identity) as GameObject;                //36+10*vx/50,200,-78+10*vz/1500),Quaternion.identity) as GameObject;
             volcanoStone v   = obj.GetComponent <volcanoStone> ();
             v.rigidbody.AddRelativeForce(vx, 0, vz);
             v.size = 2;
         }
     }
 }