【发布时间】:2014-07-11 23:23:13
【问题描述】:
我让我的玩家在屏幕上不断向下掉落,当玩家与其他游戏对象交互时,我想销毁这些游戏对象并希望玩家继续掉落。
但是当玩家击中另一个游戏对象时,游戏对象确实会被摧毁,但玩家会停止掉落。请帮助建议我做错了什么。
//Script attached to player:
//x-axis movement speed
public float playerMoveSpeed = 0.2f;
//how much force to act against the gravity
public float upForce = 9.0f;
//horizontal control
private float move;
// Update is called once per frame
void Update()
{
//player left right x-axis movement control
move = Input.GetAxis("Horizontal") * playerMoveSpeed;
transform.Translate(move, 0, 0);
}
void FixedUpdate()
{
//to fight against the gravity pull, slow it down
rigidbody.AddForce(Vector3.up * upForce);
}
//Script attached to gameObject to be destroyed on contact with player
void OnCollisionEnter(Collision col)
{
//as long as collide with player, kill object
if (col.gameObject.tag == "Player")
{
Destroy(gameObject);
}
}
【问题讨论】: