예제 #1
0
    // Update is called once per frame
    void Update()
    {
        // Detects for ground collision
        Ray        ray = new Ray(transform.position, new Vector3(0f, -(range), 0f));
        RaycastHit hit;

        if (Physics.Raycast(ray, out hit))
        {
            if (hit.distance < range)
            {
                Debug.Log("Ground detected");
                // Instance explosion sphere and destroy terrain
                explosion.transform.localScale = new Vector3(transform.lossyScale.x * 2f, transform.lossyScale.y * 2f, transform.lossyScale.z * 2f);
                Instantiate(explosion, transform.position, transform.rotation);

                mod.ReplaceBlockExplodeDown(3, hit, 0);

                //GameObject.Destroy (target);
                GameObject.Destroy(gameObject);
            }
            Debug.DrawLine(ray.origin, ray.origin + (ray.direction * hit.distance), Color.red, 2);
        }

        // Sends meteor with downwards velocity
        transform.rigidbody.velocity = new Vector3(dirX, -fallSpeed, dirZ);

        // Applies rotation to meteor
        transform.Rotate(rotX * Time.deltaTime, rotY * Time.deltaTime, rotZ * Time.deltaTime);
    }