★Toshiaki Yamasaki

(2024年4月13日)

<ホーミングミサイル>

・2秒後に追跡を開始する。

・新規にC#スクリプトを作成

・名前を「Homing」に変更

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

public class Homing : MonoBehaviour
{
    private GameObject target;
    private bool isHoming = false;

    private Rigidbody rb;

    void Start()
    {
        target = GameObject.Find("Tank");

        rb = GetComponent<Rigidbody>();

        Invoke("SwitchON", 2f);
    }

    void Update()
    {
        if(isHoming == true)
        {
            rb.velocity = Vector3.zero;

            transform.LookAt(target.transform);

            transform.Translate(Vector3.forward * Time.deltaTime * 7);
        }
    }

    void SwitchON()
    {
        isHoming = true;
    }
}

<ボスがTANKの方向に向く>

・新規にC#スクリプトを作成

・名前を「LookAT」に変更

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

public class LookAT : MonoBehaviour
{
    private GameObject target;

    void Start()
    {
        target = GameObject.Find("Tank");
    }

    void Update()
    {
        transform.LookAt(target.transform);
    }
}

<ボスがホーミングミサイルを発射する>

・新規にC#スクリプトを作成

・名前を「BossShotShell」に変更

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

public class BossShotShell : MonoBehaviour
{
    public GameObject homingPrefab;
    public AudioClip sound;

    public GameObject gyroscope;

    void Start()
    {
        StartCoroutine(Shot());
    }

    private IEnumerator Shot()
    {
        while(true)
        {
            GameObject homing = Instantiate(homingPrefab, transform.position, gyroscope.transform.rotation);

            Rigidbody homingRb = homing.GetComponent<Rigidbody>();
            homingRb.AddForce(transform.forward * 700);

            AudioSource.PlayClipAtPoint(sound, Camera.main.transform.position);

            yield return new WaitForSeconds(5f);
        }
    }
}

 


(2024年3月23日)

<The Worldの実装>

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

public class TheWorldShell : MonoBehaviour
{
    public GameObject effectPrefab;
    public AudioClip sound;
    private AudioSource audioX;

    private void Start()
    {
        // ここの設定をUnityで行う。
        audioX =  GameObject.Find("BGM").GetComponent<AudioSource>();
    }

    private void OnCollisionEnter(Collision collision)
    {
        // Dioのサウンド設定
        audioX.PlayOneShot(sound);

        GameObject effect = Instantiate(effectPrefab, transform.position, Quaternion.identity);
        Destroy(effect, 1.0f);

        this.gameObject.SetActive(false);
        
        Invoke("StopTime", 1.2f);
    }

    void StopTime()
    {
        Time.timeScale = 0;
    }
}

<Tankを動けるように改良する>

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

public class TankMoveX : MonoBehaviour
{
    private float verticalInput;
    private float horizontalInput;

    void Update()
    {
        if (Input.GetKey(KeyCode.UpArrow))
        {
            verticalInput = 1f;
        }
        else if (Input.GetKey(KeyCode.DownArrow))
        {
            verticalInput = -1f;
        }
        else
        {
            verticalInput = 0f;
        }

        if (Input.GetKey(KeyCode.LeftArrow))
        {
            horizontalInput = -1f;
        }
        else if (Input.GetKey(KeyCode.RightArrow))
        {
            horizontalInput = 1f;
        }
        else
        {
            horizontalInput = 0f;
        }

        transform.Translate(Vector3.forward * verticalInput * Time.unscaledDeltaTime * 1.2f);
        transform.Rotate(Vector3.up * horizontalInput * Time.unscaledDeltaTime * 50f);
    }
}

 

 


(2024年3月16日)

<爆風弾>

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

public class leapShell : MonoBehaviour
{
    public GameObject effectPrefab;
    public AudioClip sound;

    private float power = 15f;

    private void OnCollisionEnter(Collision collision)
    {
        GameObject effect = Instantiate(effectPrefab, transform.position, Quaternion.identity);
        Destroy(effect, 1.0f);
        AudioSource.PlayClipAtPoint(sound, transform.position);
        Destroy(this.gameObject);

        Vector3 explosionPos = collision.transform.position;
        Collider[] colliders = Physics.OverlapSphere(explosionPos, 2);

        foreach (var hit in colliders)
        {
            if (hit.gameObject.tag == "Enemy")
            {
                // 追跡機能の破壊
                NavMeshAgent agent = hit.GetComponent<NavMeshAgent>();

                if (agent)
                {
                    Destroy(agent);
                }

                Rigidbody rb = hit.gameObject.GetComponent<Rigidbody>();
                rb.isKinematic = false;
                rb.AddExplosionForce(power, collision.transform.position, 3, 1.0f, ForceMode.VelocityChange);

                Destroy(hit.gameObject, 2.0f);
            }
        }
    }
}

(設定)