魔法のメモ

CG N GAME BLOG

C#_Unity_Unit1 +a

■PlayerController.cs

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

public class PlayerController : MonoBehaviour
{
public float speed = 20.0f;
public float turnSpeed = 45.0f;
public float horizontalInput;
public float forwardInput;

// Start is called before the first frame update
void Start()
{

}

// Update is called once per frame
void Update()
{
horizontalInput = Input.GetAxis("Horizontal");
forwardInput = Input.GetAxis("Vertical");

transform.Translate(Vector3.forward * Time.deltaTime * speed * forwardInput);
//transform.Translate(Vector3.right * Time.deltaTime * turnSpeed * horizontalInput);
transform.Rotate(Vector3.up , Time.deltaTime * turnSpeed * horizontalInput);
}
}

■FollowPlayer.cs

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

public class FollowPlayer : MonoBehaviour
{
public GameObject player;
private Vector3 offset = new Vector3(0, 5, -7);

// Start is called before the first frame update
void Start()
{

}

// Update is called once per frame
void LateUpdate()
{
transform.position = player.transform.position + offset;
}
}