unity3D js代码问题
为什么grounded是false的时候if里面的代码还是执行的我把判断grounded里面的三行注释掉就不会有反应了false的话应该是不执行里面三行的吧#pragma...
为什么grounded是false的时候if里面的代码还是执行的 我把判断grounded里面的三行注释掉就不会有反应了 false的话应该是不执行里面三行的吧
#pragma strict
function Start () {
}
var speed:float=6.0;
var jumpspeed:float=8.0;
var gravity:float=20.0;
private var movedirection:Vector3=Vector3.zero;
private var grounded:boolean=false;
function FixedUpdate () {
if(grounded){
movedirection=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;
var flags=GetComponent(CharacterController).Move (movedirection * Time.deltaTime);
grounded = (flags & CollisionFlags.CollidedBelow) != 0;
}
额好吧 执行后为真了 。。。。求大神。。。。顺便问下 如果把这些代码写成C# 应该怎么写 展开
#pragma strict
function Start () {
}
var speed:float=6.0;
var jumpspeed:float=8.0;
var gravity:float=20.0;
private var movedirection:Vector3=Vector3.zero;
private var grounded:boolean=false;
function FixedUpdate () {
if(grounded){
movedirection=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;
var flags=GetComponent(CharacterController).Move (movedirection * Time.deltaTime);
grounded = (flags & CollisionFlags.CollidedBelow) != 0;
}
额好吧 执行后为真了 。。。。求大神。。。。顺便问下 如果把这些代码写成C# 应该怎么写 展开
1个回答
展开全部
using UnityEngine;
using System.Collections;
public class test : MonoBehaviour {
public float speed = 6.0f;
public float jumpspeed = 8.0f;
public float gravity = 20.0f;
private Vector3 movedirection = Vector3.zero;
private bool grounded = false;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void FixedUpdate () {
if (grounded) {
movedirection = new Vector3(Input.GetAxis("Horizonta"),0,Input.GetAxis("Vertical")) ;
movedirection = transform.TransformDirection(movedirection);
movedirection *= speed;
if(Input.GetButton("jump")){
movedirection.y = jumpspeed;
}
}
movedirection.y -= gravity * Time.deltaTime;
bool flags = GetComponent<CharacterController> ().Move (movedirection * Time.deltaTime);
grounded = (flags & CollisionFlags.CollidedBelow)! = 0;
}
}
CollisionFlags.CollidedBelow这个是什么?
using System.Collections;
public class test : MonoBehaviour {
public float speed = 6.0f;
public float jumpspeed = 8.0f;
public float gravity = 20.0f;
private Vector3 movedirection = Vector3.zero;
private bool grounded = false;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void FixedUpdate () {
if (grounded) {
movedirection = new Vector3(Input.GetAxis("Horizonta"),0,Input.GetAxis("Vertical")) ;
movedirection = transform.TransformDirection(movedirection);
movedirection *= speed;
if(Input.GetButton("jump")){
movedirection.y = jumpspeed;
}
}
movedirection.y -= gravity * Time.deltaTime;
bool flags = GetComponent<CharacterController> ().Move (movedirection * Time.deltaTime);
grounded = (flags & CollisionFlags.CollidedBelow)! = 0;
}
}
CollisionFlags.CollidedBelow这个是什么?
更多追问追答
追问
检测角色控制器的底部是否碰撞
那个flags的数据类型不对。。。不是bool float vector3。。。。究竟是什么啊
追答
昨天快下班的时候写的,没有仔细看,今天看报错了,说的这个flags的数据类型是CollisionFlags,但是最后一句也不对啊,不懂要表达什么,在js里面最后那一句没有报错吗?
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询