当我按下鼠标左键但我的球掉下来时,我试图使“第一人称控制器”炸毁(飞起来)
这用于Unity 4.5.5(我的笔记本电脑无法运行Unity的5.x.x版本)
using UnityEngine;
using System.Collections;
public class eeeboi : MonoBehaviour {
public float speed = 6.0F;
public float jumpSpeed = 8.0F;
public float gravity = 20.0F;
private Vector3 moveDirection = Vector3.zero;
public float radius;
public float force;
void Blow () {
Collider[] col = Physics.OverlapSphere (transform.position, radius);
foreach (Collider c in col) {
if (c.name != "Plane"){
c.GetComponent<Rigidbody>().AddExplosionForce (force, transform.position, radius);
}
}
}
void Update() {
CharacterController controller = GetComponent<CharacterController> ();
if (controller.isGrounded) {
moveDirection = new Vector3 (Input.GetAxis ("Horizontal"), 0, Input.GetAxis ("Vertical"));
moveDirection = transform.TransformDirection (moveDirection);
moveDirection *= speed;
if (Input.GetButton ("Jump"))
moveDirection.y = jumpSpeed;
}
moveDirection.y -= gravity * Time.deltaTime;
controller.Move (moveDirection * Time.deltaTime);
if (Input.GetMouseButtonDown (0)) {
Blow ();
}
}
}
我希望当我的球在下面时,“第一人称控制者”会飞起来,但是我的球掉下来却什么也没动