★Asuto Inukai

(2024年5月4日)

<rayヒットを検知すると、マークのサイズを大きくする>

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

[RequireComponent(typeof(CharacterController))]
[RequireComponent(typeof(AudioSource))]
public class wolk : MonoBehaviour
{
    public float ws;
    public float rs;
    private Vector3 mm;
    private CharacterController ccr;
    private AudioSource ase;
    public GameObject fpsCamera;
    public Vector3 mDr = Vector3.zero;
    public float gravity { get; set; }
    public float gracon;
    public float jp;
    private Vector3 icp;
    private bool isWalking;
    public bool swich = false;
    private float timer = 0;
    private float bbs = 10f;
    private float wbb = 0.6f;
    private float sbb = 0.2f;
    public static bool reset;
    private enum State
    {
        Nomal,
        ThrowingHook,
        FlyingPlayer,
        SpyDMode
    }
    public float hR = 400f;
    public Transform hTM;
    public Transform hs;
    private Vector3 hp;
    private float hss;
    private State state;
    public GameObject spdb;
    public Transform top;
    public GameObject aim;
    private GameObject spd;
    private Rigidbody spb;
    private float stiv;

    // ★追加(5月11日)
    public GameObject hitMarkZ;

    void Start()
    {
        gravity = 9.8f;
        ccr = GetComponent();
        ase = GetComponent();
        icp = fpsCamera.transform.localPosition;
        state = State.Nomal;
        hs.gameObject.SetActive(false);
        hTM.gameObject.SetActive(false);
        reset = true;
    }
    private void Update()
    {
        switch (state)
        {
            default:
            case State.Nomal:
                PlayerMove();
                Hb();
                Hs();
                Ssd();
                break;
            case State.ThrowingHook:
                hT();
                break;
            case State.FlyingPlayer:
                HFM();
                break;
            case State.SpyDMode:
                PSD();
                break;
        }

        // ★追加(5月11日)
        Ray ray = new Ray(fpsCamera.transform.position, fpsCamera.transform.forward);
        RaycastHit hitX;

        if (Physics.Raycast(ray, out hitX, hR))
        {
            hitMarkZ.transform.localScale = new Vector3(0.5f, 0.5f, 0.5f);
        }
        else
        {
            hitMarkZ.transform.localScale = new Vector3(0.1f, 0.1f, 0.1f);
        }

    }
    void Hb()
    {
        Vector3 ncp;
        float bba;
        if (ccr.velocity.sqrMagnitude > 0 && (mm.x != 0 || mm.z != 0))
        {

            timer += (Time.deltaTime * bbs);

            bba = isWalking ? wbb : sbb;
            fpsCamera.transform.localPosition = new Vector3(0, icp.y + Mathf.Sin(timer) * bba, 0);
            ncp = fpsCamera.transform.localPosition;
            //print("OK");
        }
        else
        {
            timer = 0;
            ncp = fpsCamera.transform.localPosition;
        }
        fpsCamera.transform.localPosition = ncp;
    }
    void PlayerMove()
    {
        float moveH = Input.GetAxis("Horizontal");
        float moveV = Input.GetAxis("Vertical");
        mm = new Vector3(moveH, 0, moveV);

        Vector3 dme = fpsCamera.transform.forward * mm.z + fpsCamera.transform.right * mm.x;
        mm.x = dme.x * 5f;
        mm.z = dme.z * 5f;
        ccr.Move(mm * Time.deltaTime * ws);
        //視点移動
        if (Input.GetKey(KeyCode.LeftShift))
        {
            ccr.Move(mDr * Time.deltaTime * rs);
        }
        else
        {
            ccr.Move(mDr * Time.deltaTime * ws);
        }
        if (ccr.isGrounded)
        {
            gracon = 0;
            if (Input.GetKeyDown(KeyCode.Space))
            {
                mDr.y = jp;
            }
        }
        else
        {
            gracon = gravity * Time.deltaTime;
            mDr.y -= gracon;
            //print(mDr.y);
            if (gracon < 0.1)
            {
                gracon = 1;
            }
            if (mDr.y < -6 || mDr.y > 20)
            {
                mDr.y = -5;
            }


        }
    }
    void Hs()
    {
        if (Input.GetMouseButtonDown(1))
        {
            RaycastHit hit;
            if (Physics.Raycast(fpsCamera.transform.position, fpsCamera.transform.forward, out hit, hR))
            {
                hTM.position = hit.point;
                hp = hit.point;
                state = State.ThrowingHook;
                hss = 0f;
                hTM.gameObject.SetActive(true);
                hs.gameObject.SetActive(true);
            }
        }
    }
    void HFM()
    {
        php php = GetComponent();
        Vector3 mD = (hp - transform.position).normalized;
        float flyingspeed = Vector3.Distance(transform.position, hp) * 2f;
        ccr.Move(mD * flyingspeed * Time.deltaTime);
        if (Input.GetMouseButtonDown(1))
        {

            Removefook();
        }
        if (Vector3.Distance(transform.position, hp) < 2f) { hs.gameObject.SetActive(false); } } void hT() { hs.LookAt(hp); float hss = 200f; hss += hss * Time.deltaTime; hs.localScale = new Vector3(1, 1, hss); if (hss >= Vector3.Distance(transform.position, hp))
        {
            state = State.FlyingPlayer;
        }
        else
        {
            Removefook();
        }
    }
    void Ssd()
    {
        if (Input.GetKeyDown(KeyCode.Q))
        {
            spd = Instantiate(spdb, top.position, transform.rotation);
            aim.SetActive(false);
            state = State.SpyDMode;
        }
    }
    void PSD()
    {
        if (spd != null)
        {
            spb = spd.GetComponent();
            stiv = Input.GetAxis("Horizontal");
            float turn = stiv * 100 * Time.deltaTime;
            Quaternion tR = Quaternion.Euler(0, turn, 0);
            spb.MoveRotation(spb.rotation * tR);

        }
        if (Input.GetKey(KeyCode.W))
        {
            spd.transform.Translate(0, 0.1f, 0);
        }
        if (Input.GetKey(KeyCode.S))
        {
            spd.transform.Translate(0, -0.1f, 0);
        }
    }
    public void Sd()
    {
        state = State.Nomal;
        aim.SetActive(true);
    }
    public void Removefook()
    {
        state = State.Nomal;
        hTM.gameObject.SetActive(false);
        hs.gameObject.SetActive(false);

    }
}

(2024年5月4日)

<ラインを引く>

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

public class Escape : MonoBehaviour
{
    public GameObject warningMark;
    public GameObject[] point;
    private NavMeshAgent agent;

    public bool go { get; set; }
    public int num { get; set; }

    private LineRenderer line;

    private int rot;

    private void Awake()
    {
        go = false;
    }

    void Start()
    {
        num = Random.Range(0, point.Length);
        agent = GetComponent<NavmeshAgent>();

        line = GetComponent<LineRenderer>();

        StartCoroutine(RotateX());
    }

    void Update()
    {
        transform.Rotate(Vector3.up * Time.deltaTime * rot);

        RaycastHit hit;
        Ray ray = new Ray(transform.position, transform.forward);

        line.SetPosition(0, ray.origin);

        if(Physics.Raycast(ray,out hit, 15))
        {
            line.SetPosition(1, hit.point);

            GameObject target = hit.collider.gameObject;

            if(target.CompareTag("Player"))
            {
                warningMark.SetActive(true);

                Invoke("GoSwitch", 1.0f);
            }
        }
        else
        {
            line.SetPosition(1, ray.origin + (ray.direction * 15));
        }

        if(go)
        {
            agent.destination = point[num].transform.position;
        }
        
    }

    void GoSwitch()
    {
        go = true;
        warningMark.SetActive(false);
    }

    private IEnumerator RotateX()
    {
        while(true)
        {
            rot = 35;

            yield return new WaitForSeconds(5f);

            rot = -35;

            yield return new WaitForSeconds(5f);
        }
    }

}