74 lines
2.0 KiB
C#
74 lines
2.0 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using TMPro;
|
|
using Random = UnityEngine.Random;
|
|
using NaughtyAttributes;
|
|
|
|
public class LobbyNPC : MonoBehaviour
|
|
{
|
|
[SerializeField] private TextMeshPro nameplate;
|
|
[SerializeField] private TextMeshPro jobPlate;
|
|
[SerializeField] private string npcName;
|
|
[SerializeField] private string npcJob;
|
|
private Animator anim;
|
|
|
|
[SerializeField] private bool isBlacksmith;
|
|
|
|
[SerializeField, ShowIf(nameof(isBlacksmith))]
|
|
private AudioSource source;
|
|
|
|
[SerializeField, ShowIf(nameof(isBlacksmith))]
|
|
private AudioClip[] hitClips;
|
|
|
|
[SerializeField, ShowIf(nameof(isBlacksmith))]
|
|
private ParticleSystem hitSparks;
|
|
|
|
void Start()
|
|
{
|
|
nameplate.text = npcName;
|
|
jobPlate.text = npcJob;
|
|
anim = GetComponent<Animator>();
|
|
}
|
|
|
|
private void Update()
|
|
{
|
|
nameplate.transform.rotation =
|
|
Quaternion.LookRotation(
|
|
(nameplate.transform.position - Player.Instance.GetPlayerFirstPersonCameraPosition()).normalized);
|
|
jobPlate.transform.rotation =
|
|
Quaternion.LookRotation((jobPlate.transform.position - Player.Instance.GetPlayerFirstPersonCameraPosition())
|
|
.normalized);
|
|
}
|
|
|
|
//animation event
|
|
public void OnEndStandPose()
|
|
{
|
|
int randAnimation = Random.Range(0, 2);
|
|
anim.SetBool("Idle1", randAnimation == 0);
|
|
anim.SetBool("Idle2", randAnimation != 0);
|
|
}
|
|
|
|
public void BlackSmithHammerHit()
|
|
{
|
|
hitSparks.Play();
|
|
int randHitClip = Random.Range(0, hitClips.Length);
|
|
source.PlayOneShot(hitClips[randHitClip]);
|
|
}
|
|
|
|
//animation event
|
|
public void OnEndIdle1Pose()
|
|
{
|
|
int randAnimation = Random.Range(0, 2);
|
|
anim.SetBool("Idle1", false);
|
|
anim.SetBool("Idle2", true);
|
|
}
|
|
|
|
//animation event
|
|
public void OnEndIdle2Pose()
|
|
{
|
|
anim.SetBool("Idle1", true);
|
|
anim.SetBool("Idle2", false);
|
|
}
|
|
} |