★Koichiro Kurose

(2023年1月15日)

<メダル落としゲーム;ボードとコインの動きを連動させる>

*動的に親子関係&関係解除でいく。

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

// このスクリプトはIs Triggerにチェックを入れたボードに追加する(ポイント)
public class BoardZ : MonoBehaviour
{
    private void OnTriggerEnter(Collider other)
    {
        if (other.CompareTag("Coin"))
        {
            other.transform.parent = transform.root;
        }
    }

    private void OnTriggerExit(Collider other)
    {
        if (other.CompareTag("Coin"))
        {
            other.transform.parent = null;
        }
    }
}

<2023_4_12>

(原因)

・プレハブデータが入っていない。

(レーダー機能の実装)

  • AddForceの「Time.deltaTime」は削除する(ポイント)
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Hassha : MonoBehaviour
{
    public float shotSpeed;
    [SerializeField]
    private GameObject shellPrefab;
    [SerializeField]
    private AudioClip shotSound;
    private int interval;

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

    // ★追加
    private void OnTriggerStay(Collider other)
    {
        if(other.TryGetComponent(out EnemyMove em))
        {
            transform.LookAt(other.transform.position);
        }
    }

    private IEnumerator Shellhassha()
    {
        yield return new WaitForSeconds(2f);
        while (true)
        {
            GameObject shell = Instantiate(shellPrefab, transform.position, Quaternion.identity);
            Rigidbody shellRb = shell.GetComponent();

            // ★修正
            // AddForceにTime.deltaTimeは使用しない。(フレームレートと関係はないので)
            shellRb.AddForce(transform.forward * shotSpeed);

            Destroy(shell, 35.0f);
            AudioSource.PlayClipAtPoint(shotSound, transform.position);

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