Aiuto su Unity 3D

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

vincyf27

Utente Attivo
240
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??
 

salmozzo

Utente Èlite
2,120
354
CPU
intel i5 3570k
Scheda Madre
gigabyte ga-z77x-d3h
HDD
ssd samsung 830 120gb
RAM
corsair vengeance 4x4gb ddr3-1600
GPU
msi radeon hd 7870 2gb gddr5 hawk
Monitor
dell u2312hm
PSU
xfx 550 watt core edition
Case
enermax hoplite eca3220
OS
windows 7 home premium
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
 

Entra

oppure Accedi utilizzando
Discord Ufficiale Entra ora!