Teachers open the door but You must enter by yourself.
【事前学習】前回学んだ機能を再確認しておきましょう。
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Mover : MonoBehaviour
{
public float speed = 20.0f;
private Rigidbody rb;
void Start(){
rb = GetComponent<Rigidbody>();
rb.velocity = transform.forward * speed;
}
}
public class PlayerController : MonoBehaviour
{
public float speed = 10.0f;
public float tilt = 4.0f;
private Rigidbody rb;
public GameObject shot;
public Transform shotSpawn;
public float fireRate=0.25f;
private float nextFire;
void Start(){
rb = gameObject.AddComponent<Rigidbody>();
}
private float moveHorizontal = 0f;
private float moveVertical = 0f;
void OnMove(InputValue movementValue){
Vector2 movementVector = movementValue.Get<Vector2>();
moveHorizontal = movementVector.x;
moveVertical = movementVector.y;
}
void OnFire(){
if (Time.time > nextFire){
nextFire = Time.time + fireRate;
Instantiate(shot,shotSpawn.position,shotSpawn.rotation);
}
}
void FixedUpdate(){
Vector3 movement = new Vector3(moveHorizontal, 0.0f, moveVertical);
rb.velocity = movement * speed;
rb.position = new Vector3(
Mathf.Clamp(rb.position.x, -6, 6),
0.0f,
Mathf.Clamp(rb.position.z, -4, 8)
);
rb.rotation = Quaternion.Euler(0.0f, 0.0f, rb.velocity.x * -tilt);
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class DestroyByBoundary : MonoBehaviour
{
private void OnTriggerExit(Collider other){
Destroy(other.gameObject);
}
}
【事後学習】本日学んだ機能を再確認しておきましょう。
This site is powered by