从脚本

时间:2018-02-15 16:29:40

标签: unity3d unityscript

我有一个游戏对象,位置和旋转最初设置为

mainModel.transform.position = new Vector3 (-3.25f,-0.2f,0.1f);
mainModel.transform.rotation = Quaternion.Euler (0,95,0);

然后我以滑动方式旋转模型

f_difX = Mathf.Abs(f_lastX - Input.GetAxis ("Mouse X"));

if (f_lastX < Input.GetAxis ("Mouse X"))
{
    i_direction = -1;

    if (yPos > (Screen.height*3 / 4)) {
        Swinginfo.SetActive (true);
        Swinginfo2.SetActive (false);
    } else if(yPos < (Screen.height*3 / 4) && yPos > (Screen.height / 4)){
        m_CurrentObj.transform.Rotate(Vector3.up, -f_difX);
    }
}

if (f_lastX > Input.GetAxis ("Mouse X"))
{
    i_direction = 1;

    if (yPos > (Screen.height*3 / 4)) {
        Swinginfo.SetActive (false);
        Swinginfo2.SetActive (true);
    } else if(yPos < (Screen.height*3 / 4) && yPos > (Screen.height / 4)){
        m_CurrentObj.transform.Rotate(Vector3.up, f_difX);
    }
}

f_lastX = -Input.GetAxis ("Mouse X")*1.5f;

模型旋转。

当我想设置其初始位置和旋转时,我设置为

mainModel.transform.position = new Vector3 (-3.25f,-0.2f,0.1f);
mainModel.transform.rotation = Quaternion.Euler (0,95,0);

但它并没有改变回初始设置。 我怎样才能拥有初始位置和轮换?

编辑:

                Debug.Log ("RangeViewScript.index "+RangeViewScript.index);
                if (RangeViewScript.index == 0) {//pass
                    mainModel.transform.position = new Vector3 (-3.25f,-0.2f,0);
                    mainModel.transform.rotation = Quaternion.Euler (0,95,0);
                    Debug.Log ("Reset 0 is called");
                }else if (RangeViewScript.index == 1) {//cheapshot
                    mainModel.transform.position = new Vector3 (-2.6f,-0.2f,0);
                    mainModel.transform.rotation = Quaternion.Euler (0,105,0);
                    Debug.Log ("Reset 1 is called");
                }else if (RangeViewScript.index == 2) {//fullswing driver
                    mainModel.transform.position = new Vector3 (-5.0f,-0.2f,0);
                    mainModel.transform.rotation = Quaternion.Euler (0,90,0);
                    Debug.Log ("Reset 2 is called");
                }else if (RangeViewScript.index == 3) {//putting
                    mainModel.transform.position = new Vector3 (-1.9f,-0.2f,0.1f);
                    mainModel.transform.rotation = Quaternion.Euler (0,95,0);
                    Debug.Log ("Reset 3 is called");
                }else if (RangeViewScript.index == 4) {//shoot
                    mainModel.transform.position = new Vector3 (-2.75f,-0.2f,0.69f);
                    mainModel.transform.rotation = Quaternion.Euler (0,100,0);
                    Debug.Log ("Reset 4 is called");
                }else if (RangeViewScript.index == 5) {//shoot
                    mainModel.transform.position = new Vector3 (-3.25f,-0.2f,0.1f);
                    mainModel.transform.rotation = Quaternion.Euler (0,95,0);
                    Debug.Log ("Reset 5 is called");
                }

0 个答案:

没有答案