• La sezione "Build Gaming" è soggetto a regolamento interno. Chiediamo di prendere visione prima di aprire una discussione.

Aiuto su Unity 3D

Pubblicità

vincyf27

Utente Attivo
Messaggi
240
Reazioni
14
Salve, è la prima volta che uso unity3D, lo sto utilizzando per fare un gioco 2D. C'è qualcuno che lo sa usare vorrei farmi aiutare su degli script.
Piu precisamente lo script per muovermi perche ne ho fatto uno e mi riesco a muovere a destra e sinistra ma non riesco a saltare lo script è questo:


using UnityEngine;
using System.Collections;

public class Controller : MonoBehaviour {

private float hspeed, vspeed;
private const float SPEED = 4;
private const float JUMP_SPEED = 20;
private bool grounded;
private const float RAY_LENGTH = 0.5f;
void Start () {
hspeed = 0;
vspeed = 0;
grounded = false;
}

// Update is called once per frame
void Update () {
IsGrounded ();
if (Input.GetKey ("a")) {
hspeed = -SPEED;
} else if (Input.GetKey ("d")) {
hspeed = SPEED;
} else {
hspeed= 0;
}
if (Input.GetKey ("w") && grounded) {
vspeed = 5;
} else {
vspeed = 0;
}
GetComponent<Rigidbody2D>().velocity = new Vector3 (hspeed, GetComponent<Rigidbody2D>().velocity.y, 0);

}
bool IsGrounded(){
Vector3 position = transform.position + Vector3.down * 0.5f;
grounded = Physics2D.Raycast (position, Vector3.down, RAY_LENGTH);
Color col = Color.green;
if (grounded)col = Color.red;
Debug.DrawRay(position, Vector3.down*RAY_LENGTH, col);

return grounded;
}
}



Cosa ho sbagliato??
 
Salve, è la prima volta che uso unity3D, lo sto utilizzando per fare un gioco 2D. C'è qualcuno che lo sa usare vorrei farmi aiutare su degli script.
Piu precisamente lo script per muovermi perche ne ho fatto uno e mi riesco a muovere a destra e sinistra ma non riesco a saltare lo script è questo:


using UnityEngine;
using System.Collections;

public class Controller : MonoBehaviour {

private float hspeed, vspeed;
private const float SPEED = 4;
private const float JUMP_SPEED = 20;
private bool grounded;
private const float RAY_LENGTH = 0.5f;
void Start () {
hspeed = 0;
vspeed = 0;
grounded = false;
}

// Update is called once per frame
void Update () {
IsGrounded ();
if (Input.GetKey ("a")) {
hspeed = -SPEED;
} else if (Input.GetKey ("d")) {
hspeed = SPEED;
} else {
hspeed= 0;
}
if (Input.GetKey ("w") && grounded) {
vspeed = 5;
} else {
vspeed = 0;
}
GetComponent<Rigidbody2D>().velocity = new Vector3 (hspeed, GetComponent<Rigidbody2D>().velocity.y, 0);

}
bool IsGrounded(){
Vector3 position = transform.position + Vector3.down * 0.5f;
grounded = Physics2D.Raycast (position, Vector3.down, RAY_LENGTH);
Color col = Color.green;
if (grounded)col = Color.red;
Debug.DrawRay(position, Vector3.down*RAY_LENGTH, col);

return grounded;
}
}



Cosa ho sbagliato??

a usare unity
usa unreal engine 4
 
Pubblicità
Pubblicità
Indietro
Top