250226

lililllilillll·2025년 2월 26일

개발 일지

목록 보기
94/350

✅ 오늘 한 일


  • Project BCA


🎮 Project BCA


Completing main game

  • 컴퓨터 green material 깜빡이기
    • 머테리얼을 건드렸더니 게임이 꺼져도 그대로 유지돼서 대신 MaterialPropertyBlock 사용
    • MaterialPropertyBlock을 사용할 때 Renderer에 여러 개의 머테리얼이 적용되어 있다면, 특정 머테리얼의 인덱스를 지정해서 변경해야함
using UnityEngine;
using DG.Tweening;

public class ComputerGlitter : MonoBehaviour
{
    [SerializeField] private Renderer objectRenderer;
    [SerializeField] private float minIntensity = 0.5f;
    [SerializeField] private float maxIntensity = 1.5f;
    [SerializeField] private float minDuration = 0.5f;
    [SerializeField] private float maxDuration = 1.5f;
    private int materialIndex = 4;

    private MaterialPropertyBlock propBlock;
    private Color baseColor;

    void Start()
    {
        propBlock = new MaterialPropertyBlock();
        objectRenderer.GetPropertyBlock(propBlock, materialIndex);
        baseColor = objectRenderer.sharedMaterials[materialIndex].GetColor("_EmissionColor");

        StartGlitterEffect();
    }

    void StartGlitterEffect()
    {
        float intensity = (Random.value > 0.5f) ? minIntensity : maxIntensity;
        float duration = Random.Range(minDuration, maxDuration);
        propBlock.SetColor("_EmissionColor", baseColor * intensity);
        objectRenderer.SetPropertyBlock(propBlock, materialIndex);

        DOVirtual.DelayedCall(duration, StartGlitterEffect);
    }
}
    public void PlayShooterFootstep()
    {
        if (currentClipIndex >= footstep_sounds.Count)
        {
            currentClipIndex = 0;
            DOVirtual.DelayedCall(reloadDelay, PlayShooterReload);
            return;
        }

        AudioClip clip = footstep_sounds[currentClipIndex];
        audioSource.clip = clip;
        // audioSource.volume = (currentClipIndex + 1) * footstepIncrement;
        audioMixer.SetFloat("ShooterVolume", footstep_volume + footstepIncrement * (currentClipIndex + 1));
        audioSource.Play();
        DOVirtual.DelayedCall(clip.length + gapBetweenFootsteps, PlayShooterFootstep);

        currentClipIndex++;
    }

    private void PlayShooterReload()
    {
        audioMixer.SetFloat("ShooterVolume", reload_volume);
        audioSource.clip = reloadSound;
        audioSource.Play();
        DOVirtual.DelayedCall(reloadSound.length + shotDelay, PlayShooterShot);
    }

    private void PlayShooterShot()
    {
        audioMixer.SetFloat("ShooterVolume", shot_volume);
        audioSource.clip = shotSound;
        audioSource.Play();
    }
profile
너 정말 **핵심**을 찔렀어

0개의 댓글