実技(Unity実習)16

1.AI機能
2.NavMesh
3.親子関係
4.爆発力の伝搬
5.プレハブからオリジナルプレファブ

1.府中(遅刻)
2.
3.
4.
5.

PlayerController.cs

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

public class PlayerController : MonoBehaviour
{
    public GameObject prefab;
    void Update()
    {
       transform.Translate(Input.GetAxis("Horizontal") * Time.deltaTime, 0, 0);
        if (Input.GetButtonDown("Fire1")) {
            GameObject obj = Instantiate(prefab);
            obj.transform.SetParent(transform);
            obj.transform.localPosition = Vector3.up;
        }
    }
}

SphereController.cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class SphereController : MonoBehaviour
{
    Rigidbody rb;
  
    void Start()
    {
        rb = GetComponent<Rigidbody>();
    }

    void Update()
    {
        if (Input.GetButtonDown("Jump")) {
            rb.velocity = new Vector3(0, 1.0f, 1.0f) * 10f;
        }
    }
}

CcSphereController.cs

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

public class CcSphereController : MonoBehaviour
{
    CharacterController cc;
    // Start is called before the first frame update
    void Start()
    {
        cc = GetComponent<CharacterController>();
    }

    // Update is called once per frame
    void Update()
    {
        cc.Move(Vector3.zero);
    }
}