这是我的玩家移动的代码:
var animator : Animator;
function Start () {
animator = GetComponent("Animator");
}
var moveUp : KeyCode;
var moveDown : KeyCode;
var moveLeft : KeyCode;
var moveRight : KeyCode;
var jumpheight : int = 2;
var speed : int = 2;
var isGrounded : int = 0;
// Checks if player is in air or ground
var Jumptest : int = 0;
// Checks if player has jumped
function Update () {
animator.SetInteger("Direction", 4);
if (Input.GetKey(moveUp) && isGrounded == 0)
{
rigidbody2D.velocity.y = jumpheight;
isGrounded = 1;
animator.SetInteger("Direction", 2);
}
else if (Input.GetKey(moveLeft))
{
transform.position += Vector3.left * speed * Time.deltaTime;
animator.SetInteger("Direction", 3);
}
else if (Input.GetKey(moveRight))
{
transform.position += Vector3.right * speed * Time.deltaTime;
animator.SetInteger("Direction", 1);
}
}
这是弹丸运动的代码:
#pragma strict
var speed = 8.0;
var time = 0.0;
function Start () {
}
var moveRight : KeyCode;
var moveLeft : KeyCode;
function Update () {
time += Time.deltaTime;
if(time > 3){
Destroy(gameObject);
}
transform.Translate(Vector3.right * speed * Time.deltaTime, Space.Self);
}
此刻,弹丸向右射击。我希望能够朝玩家所面对的方向射击它们。
我尝试了 if key down a 和 if key down d 但是当玩家不移动并相对于玩家移动时弹丸停止(如果我向左射击,然后将我的玩家向右移动,弹丸反转方向)。
有人知道吗?