microsft c# user manual code example
Example 1: c#
if your looking for C# or C++ compiler IDE I would suggest visual studio 2019.
Example 2: C#
using System.Collections;
using System.Collections.genric;
using Unityengine;
public class examplescript : monobehavior
public float speed = 5;
public float gravity = -5;
float velocityY = 0;
CharacterController controller;
void Start()
{
controller = GetComponent();
}
void Update()
{
velocityY += gravity * Time.deltaTime;
Vector3 input = new Vector3(Input.GetAxisRaw("Horizontal"), 0 Input.GetAxisRaw("Vertical"));
input = input.normalized;
Vector3 temp = Vector3.zero;
if (input.z == 1)
{
temp += transform.forward;
}
else if (input.z == -1)
{
temp += transform.forward * -1;
}
if (input.x == 1)
{
temp += transform.right;
}
else if (input.x == -1)
{
temp += transform.right * -1;
}
Vector3 velocity = temp * speed;
velocity.y = velocityY;
controller.Move(velocity * Time.deltaTime);
if (controller.isGrounded)
{
velocityY = 0;
}
private void Update() {
Rigidbody rb = GetComponent();
if (Input.GetKey(KeyCode.A))
rb.AddForce(Vector3.left);
if (Input.GetKey(KeyCode.D))
rb.AddForce(Vector3.right);
if (Input.GetKey(KeyCode.W))
rb.AddForce(Vector3.up);
if (Input.GetKey(KeyCode.S))
rb.AddForce(Vector3.down);
}