敵に発見されたら画面を赤くする
視界を赤く変化させる
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
// ★追加(視界を赤くする)
using UnityEngine.Rendering.PostProcessing;
public class EnemyCore : MonoBehaviour
{
public float lockRange;
public AudioClip alert;
private AudioSource audioS;
public Vector3 rot;
// ★追加(視界を赤くする)
private PostProcessVolume processVolume;
public PostProcessProfile alertFile;
private void Start()
{
audioS = GetComponent<AudioSource>();
// ★追加(視界を赤くする)
processVolume = GameObject.Find("PPManager").GetComponent<PostProcessVolume>();
}
void Update()
{
transform.Rotate(rot * Time.deltaTime);
RaycastHit hit;
Ray ray = new Ray(transform.position, transform.forward);
if(Physics.Raycast(ray, out hit, lockRange))
{
GameObject target = hit.collider.gameObject;
if(target.CompareTag("PlayerBody"))
{
GetComponent<MeshRenderer>().material.color = Color.red;
audioS.clip = alert;
audioS.Play();
// ★追加(視界を赤くする)
processVolume.profile = alertFile;
}
}
}
}
【2021版】X_Mission(全34回)
他のコースを見る視界を赤く変化させる
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
// ★追加(視界を赤くする)
using UnityEngine.Rendering.PostProcessing;
public class EnemyCore : MonoBehaviour
{
public float lockRange;
public AudioClip alert;
private AudioSource audioS;
public Vector3 rot;
// ★追加(視界を赤くする)
private PostProcessVolume processVolume;
public PostProcessProfile alertFile;
private void Start()
{
audioS = GetComponent<AudioSource>();
// ★追加(視界を赤くする)
processVolume = GameObject.Find("PPManager").GetComponent<PostProcessVolume>();
}
void Update()
{
transform.Rotate(rot * Time.deltaTime);
RaycastHit hit;
Ray ray = new Ray(transform.position, transform.forward);
if(Physics.Raycast(ray, out hit, lockRange))
{
GameObject target = hit.collider.gameObject;
if(target.CompareTag("PlayerBody"))
{
GetComponent<MeshRenderer>().material.color = Color.red;
audioS.clip = alert;
audioS.Play();
// ★追加(視界を赤くする)
processVolume.profile = alertFile;
}
}
}
}
敵に発見されたら画面を赤くする