12-12-2014, 11:26 AM
Ma da quel codice devo aggiungere tipo questa cosa per farlo muovere?
using UnityEngine;
using System.Collections;
public class Controller : MonoBehaviour {
private float hspeed, vspeed; // velocità orrizzontale e verticale
private const float SPEED = 2; // velocità massima del movimento
void Start () {
// Inizialmente il personaggio non si muove -> le velocità sono = 0!
hspeed = 0;
vspeed = 0;
}
void Update () {
if (Input.GetKey ("left")) {
hspeed = -SPEED;
} else if (Input.GetKey("right")) {
hspeed = SPEED;
} else {
hspeed = 0;
}
rigidbody2D.velocity = new Vector3(hspeed, rigidbody2D.velocity.y, 0);
}
}
using UnityEngine;
using System.Collections;
public class Controller : MonoBehaviour {
private float hspeed, vspeed; // velocità orrizzontale e verticale
private const float SPEED = 2; // velocità massima del movimento
void Start () {
// Inizialmente il personaggio non si muove -> le velocità sono = 0!
hspeed = 0;
vspeed = 0;
}
void Update () {
if (Input.GetKey ("left")) {
hspeed = -SPEED;
} else if (Input.GetKey("right")) {
hspeed = SPEED;
} else {
hspeed = 0;
}
rigidbody2D.velocity = new Vector3(hspeed, rigidbody2D.velocity.y, 0);
}
}