★Erika Hamanaka

(2024年4月27日)

<敵をジャンプ移動させる>

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

public class MoveXXX : MonoBehaviour
{
    private Rigidbody rb;

    void Start()
    {
        rb = GetComponent<Rigidbody>();

        StartCoroutine(MoveJump());
    }

    private IEnumerator MoveJump()
    {
        while(true)
        {
            rb.velocity = transform.up * 4 + transform.forward * 4;

            yield return new WaitForSeconds(0.5f);

            rb.velocity = Vector3.zero;

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

 


(2024年4月20日)

<敵を巡回させる>

(アニメーションの修正)

・Rigidbodyが付いていると、うまく移動しないので外す(ポイント)

(敵の角度を変更するスクリプト)

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

public class TurnPoint : MonoBehaviour
{
    public Quaternion turnValue;

    void OnTriggerEnter(Collider other)
    {
        if (other.CompareTag("EnemyXXX"))
        {
            other.transform.rotation = turnValue;
        }
    }
}

(設定)

 


(2024年2月24日)

<人型のキャラを動かす>

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

public class PlayerMovent : MonoBehaviour
{
    private CharacterController controller;

    private void Start()
    {
        controller = GetComponent<CharacterController>();
    }

    void Update()
    {
        float moveH = Input.GetAxis("Horizontal");
        float moveV = Input.GetAxis("Vertical");

        controller.Move(transform.forward * moveV * Time.deltaTime * 5);

        transform.Rotate(Vector3.up * moveH * 2);
    }
}


(2023年7月15日)

<会話システム>

(スクリプト)

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

public class TextController : MonoBehaviour
{
    public Text textLabel;
    public string charaName;
    public string[] word;
    public AudioClip sound;
    private int num = 0;

    private void Start()
    {
        textLabel.text = charaName + "\n" + word[num];
    }

    void Update()
    {
        if(Input.GetKeyDown(KeyCode.Space))
        {
            if(num == word.Length - 1)
            {
                return;
            }

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

            num += 1;

            textLabel.text = charaName + "\n" + word[num];            
        }
    }
}

(2023年5月13日)

<Optionキーで、画面の周回をすることができない>

(原因)

・シーンギズモの回転がロックされている。

(解決法)

・ロックを解除すればOK

 

 


(2023年4月29日)

<フィールドと屋内でBGMを切り替える>

(ポイント)名前の一部に特定の文字が含まれる場合の条件記載方法

(スクリプト1)

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

public class BGMController : MonoBehaviour
{
    public AudioClip fieldSound;
    public AudioClip houseSound;

    private AudioSource audioS;

    void Start()
    {
        audioS = GetComponent<AudioSource>();

        // ゲームスタート時はハウスサウンド
        audioS.clip = houseSound;
        audioS.Play();
    }

    // 外部からBGMを変更するメソッド
    // フィールドサウンドに変更
    public void ChangeFieldSound()
    {
        audioS.clip = fieldSound;
        audioS.Play();
    }

    // ハウスサウンドに変更
    public void ChangeHouseSound()
    {
        audioS.clip = houseSound;
        audioS.Play();
    }
}

(設定)

・このスクリプトはCreate Emptyで作成したオブジェクトに追加する。


(スクリプト2)

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

public class HitManager : MonoBehaviour
{
    public GameObject bgmController;
    private bool isFieldSound = false;

    private void OnControllerColliderHit(ControllerColliderHit hit)
    {
        print(hit.gameObject.name);

        // 名前が合致していた場合
        if(hit.gameObject.name == "Field" && isFieldSound == false)
        {
            bgmController.GetComponent<BGMController>().ChangeFieldSound();

            isFieldSound = true;
        }

        // 名前の一部に特定の文字が含まれている場合
        if(hit.gameObject.name.Contains("home") && isFieldSound == true)
        {
            bgmController.GetComponent<BGMController>().ChangeHouseSound();

            isFieldSound = false;
        }
    }
}

(設定)

・このスクリプトはPlayerに追加する。

・空欄にはBGMControllerオブジェクトを追加する。