Unity 简单手机小游戏 - 3D重力滚球(源码)

2020-10-21 11:16发布

游戏效果图: 需要的可以素材的可以留言,评论,,目前做了5个关卡

通过陀螺仪使得小球有运动的力

public class groy : MonoBehaviour {

 

        float x;

        float y;

        Gyroscope go;

        void Start()

        {

            go = Input.gyro;

            go.enabled = true;

        }

        void Update()

        {

            x = Input.acceleration.x;

            y = Input.acceleration.y;

            this.GetComponent<Rigidbody>().AddForce(new Vector3(-x, 0, -y) * 20);

        }

 

}


开始的UI场景,应用于按钮(开始,和游戏结束)

 

public class StartUi : MonoBehaviour {

 

    public void Reaply()

    {

        Time.timeScale = 1;

        Application.LoadLevel(1);

       

    }

    public void Quit()

    {

        Application.Quit();

    }

}


 

用触发器时刻判断,进洞重新开始,到终点弹出重玩,下一关按钮进行选择,用GUI制作了简易放回主菜单(回到场景0)按键,,

 

public class Mover : MonoBehaviour {

 

    public GameObject go;

  

    private void OnTriggerStay(Collider other)

    {

        if (other.name == "target")

        {

            go.gameObject.SetActive(true);

            Time.timeScale = 0;

        }

        else

        {

            Application.LoadLevel(1);

        }

    }

    private void OnTriggerEnter(Collider other)

    {

        if (other.name == "target")

        {

            go.gameObject.SetActive(true);

            Time.timeScale = 0;

        }

        else

        {

            Application.LoadLevel(1);

        }

    }

 

    private void OnGUI()

    {

        GUIStyle style = new GUIStyle();

        style.fontSize = 36;

        if (GUI.Button(new Rect(50,30, 200,80 ), "返回菜单",style)){

            Application.LoadLevel(0);

        }    

      

    }

}



作者:Czhenya

链接:https://czhenya.blog.csdn.net/article/details/77408315

来源:CSDN
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。