16-06-2015, 08:09 PM
Ecco l'intero script:
using UnityEngine;
using System.Collections;
public class Movement : MonoBehaviour {
public float moveSpeed;
public GameObject particle;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
if (Input.GetKey(KeyCode.W))
{
transform.Translate(Vector3.forward * Time.deltaTime*moveSpeed);
Ray ras = new Ray(transform.position,Vector3.forward);
Debug.DrawRay(ras.origin, ras.direction * 10, Color.yellow);
}
if (Input.GetKey(KeyCode.S))
{
transform.Translate(-Vector3.forward * Time.deltaTime*moveSpeed);
}
if (Input.GetKey(KeyCode.A))
{
transform.Translate(-Vector3.right * Time.deltaTime*moveSpeed);
}
if (Input.GetKey(KeyCode.D))
{
transform.Translate(Vector3.right * Time.deltaTime*moveSpeed);
}
if (Input.GetButtonDown("Fire1")) {
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
if (Physics.Raycast(ray)){
Instantiate(particle, transform.position, transform.rotation);
}
}
}
}
using UnityEngine;
using System.Collections;
public class Movement : MonoBehaviour {
public float moveSpeed;
public GameObject particle;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
if (Input.GetKey(KeyCode.W))
{
transform.Translate(Vector3.forward * Time.deltaTime*moveSpeed);
Ray ras = new Ray(transform.position,Vector3.forward);
Debug.DrawRay(ras.origin, ras.direction * 10, Color.yellow);
}
if (Input.GetKey(KeyCode.S))
{
transform.Translate(-Vector3.forward * Time.deltaTime*moveSpeed);
}
if (Input.GetKey(KeyCode.A))
{
transform.Translate(-Vector3.right * Time.deltaTime*moveSpeed);
}
if (Input.GetKey(KeyCode.D))
{
transform.Translate(Vector3.right * Time.deltaTime*moveSpeed);
}
if (Input.GetButtonDown("Fire1")) {
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
if (Physics.Raycast(ray)){
Instantiate(particle, transform.position, transform.rotation);
}
}
}
}