Hi everybody.
I’m making a script (it’s at the bottom of the comment) which is going to move a Sphere in a soccer field using arrow keys.
How can I write that in the Script?
With some comment in the Script I explain my problem better.
Sorry for my bed English but I’m form Italy.
SCRIPT:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class MovBall2Script : MonoBehaviour {
private Rigidbody rigidB;
public int speed = 10;
public int Score;
void Start () {
rigidB = GetComponent();
}
// Update is called once per frame
void Update () {
if(Input.GetKey(“W”)){ \ I want change “W” with “Arrow up”
rigidB.AddForce(Vector3.forward * speed);
}
if(Input.GetKey(“S”)){ \ I want to change “S” with “Arrow Down”
rigidB.AddForce(Vector3.back * speed);
}
if(Input.GetKey(“D”)){ \ I want to change “D” with “Arrow right”
rigidB.AddForce(Vector3.right *speed);
}
if(Input.GetKey(“A”)){ \ I want to change “A” with “Arrow left”
rigidB.AddForce(Vector3.left *speed);
}
}
}
See you soon
-Vipera74