unity跳跃按钮_Unity中实现3D物体跳跃

目前主要实现的是鼠标点击任何地方 所绑定的物体都会跳跃(点击的越快,物体就回在上次点击的基础之上在进行等比的高度增加)。

代码如下:

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);

}

}

},如果通过按钮控制物体跳跃,是需要使用工具实现那,还是需要自己修改(请读者给予建议)?

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值