Clase 1

Pasos

  • Crear nuevo proyecto 3D
  • Importar entorno y crear entorno (aprender navigar Unity)
  • Importar judagor y añadir texturas y Character Controller (colisionador y SimpleMove)

Clase 2

Vídeo clase 2

  • Cambiar la posición del Character Controller (height: 1, Center Y: 0.5). Así el colisionador (Collider) cubre el personaje.
  • Añadir un script al personaje llamada PlayerController.
  • Encuentra el script en la carpeta Assets, en la pantalla Project, y ábrelo (va a abrirse en Visual Studio automáticamente).

Ve que ya contiene este código:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PlayerController : MonoBehaviour
{
    // Start is called before the first frame update
    void Start()
    {
        
    }

    // Update is called once per frame
    void Update()
    {
        
    }
}
  • Pon Debug.Log("Start!"); en Start() { ... }. y observa el efecto en la consola (Console).
  • Pon este código en Update() { ... }. y observa el efecto en la consola (Console).:
float speed = Input.GetAxis("Vertical");

if (speed != 0) // el jugador se mueve
{
    Debug.Log(speed);
}
  • Hacer movimiento vertical (cambiar el color en Playmode)
  • Hacer rotación
  • Hacer variables para velocidad y rotación
  • Conectar animaciones (Añadir controller de animación)
  • Mover cámara con jugador

Código Completo

// PlayerController.cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PlayerController : MonoBehaviour
{
    public float moveSpeed = 4.0f;
    public float rotateSpeed = 1.0f;

    // Start is called before the first frame update
    void Start()
    {
        //Debug.Log("Start!");

        Animator anim = GetComponent<Animator>();

        anim.SetBool("Grounded", true);
    }

    // Update is called once per frame
    void Update()
    {
        float speed = Input.GetAxis("Vertical");

        Animator anim = GetComponent<Animator>();

        anim.SetFloat("MoveSpeed", speed);

        transform.Rotate(0, Input.GetAxis("Horizontal") * rotateSpeed, 0);

        //if (speed != 0) // el jugador se mueve
        //{
        //    Debug.Log(speed);
        //}

        Vector3 forward = transform.TransformDirection(Vector3.forward);

        CharacterController controller = GetComponent<CharacterController>();
        controller.SimpleMove(forward * speed * moveSpeed);
    }
}