VR 游戏本地存档

8 篇文章 0 订阅
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using System;

public class Rigth_hand : MonoBehaviour {
    public static Rigth_hand instance;
    SteamVR_TrackedObject trackobject;
    SteamVR_Controller.Device device;
    private bool stopzhendong;
    public GameObject feibiao;
    private Quaternion rotation;
    private GameObject obj;
    public GameObject cube;
    private int number;

    public GameObject uichengji;
    public Text textTotalScores;
    public Text onenumber;
    
    public int one;
    public Text twonumber;
    public int two;
    public Text threenumber;
    public int three;
    public Text fournumber;
    public int four;

    public Text zuigaofen;
    private int lishizuigao;
    private int scores=0;
    private int numberscores;
    private bool stop;


    // private bool fei;
    // Use this for initialization
    void Start () {
        instance = this;
        if (PlayerPrefs.GetInt("Scores")==0)
        {
            PlayerPrefs.SetInt("Scores", scores);
        }
       

        trackobject = transform.GetComponent<SteamVR_TrackedObject>();
        rotation = new Quaternion();
        rotation.eulerAngles = new Vector3(90,0,0);
    }
    
    // Update is called once per frame
    void Update () {
        Shexian();
        if (obj != null)
        {
            obj.transform.LookAt(cube.transform);
        }
    }
    void Shexian()
    {
        try
        {
            device = SteamVR_Controller.Input((int)trackobject.index);
        }
        catch (System.Exception)
        {

            throw;
        }
        if (device.GetPressDown(SteamVR_Controller.ButtonMask.Trigger))
        {
            number++;
            if (number <= 20)
            {
                //fei = false;
                obj = GameObject.Instantiate(feibiao, transform.position+new Vector3(0,0.05f,0), transform.rotation);
                obj.transform.SetParent(transform);
                stop = true;
                SnyScores();
            }
            else
            {
                if (stop == true)
                {
                   
                    print("stop");
                   

                    if (scores> PlayerPrefs.GetInt("Scores", 0))
                    {

                        PlayerPrefs.SetInt("Scores", scores);

                                    
                        print("进来了");                 
                    }
                    lishizuigao = PlayerPrefs.GetInt("Scores", 0);
                    zuigaofen.text = "Highest:" + lishizuigao;
                    stop = false;
                    uichengji.SetActive(true);

                }
            }
            stopzhendong = true;
           
        }
        if (device.GetPressUp(SteamVR_Controller.ButtonMask.Trigger))
        {
           
            stopzhendong = false;
            if (obj != null)
            {
                if(number <= 20)
                {
                    //fei = true;
                    obj.GetComponent<Rigidbody>().isKinematic = false;

                    obj.transform.SetParent(null);
                    tossObject(obj.GetComponent<Rigidbody>());
                }
                
            }
        }



        if (stopzhendong==true)
        {
            device.TriggerHapticPulse(500); 
        }
        //if (fei == true)
        //{
        //    obj.transform.GetComponent<Rigidbody>().AddRelativeForce(Vector3.down * 500);
        //    print("111");
        //}
    }
    void tossObject(Rigidbody rigidbody)
    {
        
        //如果是起始位置,则设置为起始位置,否则设置为父类  
        Transform origin = trackobject.origin ? trackobject.origin : trackobject.transform.parent;

        //如果起始位置部位空  
        if (origin != null)
        {
            //将局部坐标转换成世界坐标  
            rigidbody.velocity = origin.TransformVector((device.velocity*5));
            rigidbody.angularVelocity = origin.TransformVector((device.angularVelocity*5));
        }
        else
        {
            //设置速度  
            rigidbody.velocity = device.velocity;
            //设置角速度  
            rigidbody.angularVelocity = device.angularVelocity;
        }
        
    }
    void SnyScores()
    {
        onenumber.text ="1 Point:"+ one;
        twonumber.text = "2 Point:" + two;
        threenumber.text = "3 Point:" + three;
        fournumber.text = "4 Point:" + four;
      
        textTotalScores.text ="Total: "+(one + two + three + four);
        numberscores = Convert.ToInt32(one + two + three + four);
        //zongfen
        scores = numberscores;
        lishizuigao = scores;
    }
}



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值