构建后脚本无法完全运行 (Unity / C#)
script doesnt work fully after build (Unity / C#)
所以昨天我为 gamejam 完成了我的第一个游戏,我构建了它并将它上传到 itch.io。但是当我回到今天时,我看到一条消息说我的玩家移动不起作用,而它在 unity 内部起作用。播放构建后,我还注意到这是行不通的。但是我就是不知道为什么不行,所以有什么可能让它不起作用。
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Player_Movement : MonoBehaviour
{
public Rigidbody rb;
public float X_Axis;
public float Z_Axis;
public float force;
public bool Forward_backward;
public bool leftward_rightward;
void Start()
{
GetComponent<Rigidbody>().freezeRotation = true;
Forward_backward = true;
leftward_rightward = true;
force = 5f;
}
public void Update()
{
//Sideward
if (Input.GetKey ("a"))
{
if (leftward_rightward == true)
{
leftward_rightward = false;
Debug.Log("leftward_rightward is false");
}
}
if (Input.GetKey("d"))
{
if (leftward_rightward == false)
{
leftward_rightward = true;
Debug.Log("leftward_rightward is true");
}
}
if (leftward_rightward == true)
{
X_Axis = force;
}
if (leftward_rightward == false)
{
X_Axis = force * -1;
}
Vector3 movement = new Vector3(Input.GetAxis("Horizontal"), 0f, 0f);
if (Input.GetKey("w"))
{
rb.AddForce(new Vector3(0f, 0f, Z_Axis));
}
if (Input.GetKey("s"))
{
rb.AddForce(new Vector3(X_Axis, 0f, 0f));
}
}
注意:a和d键的输入有效,但这是切换bool。真正的运动(w和s)不起作用。
我试着查看游戏日志,但我找不到任何东西
问题是力量对编辑器来说足够大但对构建版本来说不够大,增加添加到播放器的力量解决了这个问题。
所以昨天我为 gamejam 完成了我的第一个游戏,我构建了它并将它上传到 itch.io。但是当我回到今天时,我看到一条消息说我的玩家移动不起作用,而它在 unity 内部起作用。播放构建后,我还注意到这是行不通的。但是我就是不知道为什么不行,所以有什么可能让它不起作用。
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Player_Movement : MonoBehaviour
{
public Rigidbody rb;
public float X_Axis;
public float Z_Axis;
public float force;
public bool Forward_backward;
public bool leftward_rightward;
void Start()
{
GetComponent<Rigidbody>().freezeRotation = true;
Forward_backward = true;
leftward_rightward = true;
force = 5f;
}
public void Update()
{
//Sideward
if (Input.GetKey ("a"))
{
if (leftward_rightward == true)
{
leftward_rightward = false;
Debug.Log("leftward_rightward is false");
}
}
if (Input.GetKey("d"))
{
if (leftward_rightward == false)
{
leftward_rightward = true;
Debug.Log("leftward_rightward is true");
}
}
if (leftward_rightward == true)
{
X_Axis = force;
}
if (leftward_rightward == false)
{
X_Axis = force * -1;
}
Vector3 movement = new Vector3(Input.GetAxis("Horizontal"), 0f, 0f);
if (Input.GetKey("w"))
{
rb.AddForce(new Vector3(0f, 0f, Z_Axis));
}
if (Input.GetKey("s"))
{
rb.AddForce(new Vector3(X_Axis, 0f, 0f));
}
}
注意:a和d键的输入有效,但这是切换bool。真正的运动(w和s)不起作用。
我试着查看游戏日志,但我找不到任何东西
问题是力量对编辑器来说足够大但对构建版本来说不够大,增加添加到播放器的力量解决了这个问题。