目前主要实现的是鼠标点击任何地方 所绑定的物体都会跳跃(点击的越快,物体就回在上次点击的基础之上在进行等比的高度增加)。
代码如下:
using UnityEngine;
using System.Collections;
public class CylinderMove : MonoBehaviour {
private float speed = 5f;
private Rigidbody body;
public static CylinderMove instance;
public static CylinderMove Instance
{
get
{
if(instance == null)
{
instance = new CylinderMove();
}
return instance;
}
}
// Use this for initialization
void Start ()
{
body = transform.GetComponent();
}
// Update is called once per frame
void Update ()
{
if(Input.GetMouseButtonDown(0))
{
Debug.Log("ssss");
JumpFunc();
}
Debug.DrawRay(transform.position,Vector3.down,Color.black);
}
public void JumpFunc()
{
RaycastHit hit;
if(Physics.Raycast(transform.position,Vector3.down,out hit))
{
body.AddForce(Vector3.up * 3000);
}
}
},如果通过按钮控制物体跳跃,是需要使用工具实现那,还是需要自己修改(请读者给予建议)?