Utilizing Faiyth’s addons for ummorpg has been an uphill battle. There are so many great options available through this package, but they conflict with a lot of other assets we are already using. There’s also a lot of options available in her package that require a lot of fine tuning to work properly. However we now have hitboxes on the weapons that should work precisely in combat. This is awesome for the player because now you will see damage produced when collisions occur.
Month: January 2021
Animator Quick Fix
sometimes the standalone player will turn off the animator for npc’s and monsters. The easiest quick fix for this problem is to force them on. Here is the quick solution, and it really works wonders.
public class animatorfixer : MonoBehaviour
{
public Animator anim;
// Start is called before the first frame update
void Start()
{
anim = GetComponent<Animator>();
anim.enabled = true;
}
}
Audio with Unity
To incorporate the sounds into this game a custom script was written which handles the audio clips. There is a Master clip and 2 children.
public class zonemusic1 : MonoBehaviour
{
public audiomaster audiomaster;
public AudioClip clip1;
void OnTriggerEnter(Collider other)
{
if (other.CompareTag("Player"))
{
audiomaster.play(clip1); //from audiomaster
}
}
void OnTriggerExit(Collider other)
{
if (other.CompareTag("Player"))
{
audiomaster.stop();
}
}
}
zone music handles the audio source collision logic for the audio master. There are 3 empty game objects, one parent and two children. The variables for the audio source and audio master are assigned in the inspector window as follows.
The sound master uses the following code to handle playing the first song throughout the login/character selection/and first zone. This seamless transition is then altered when collisions are detected n the zonemusic class. There is logic for a slider that is then assigned for the soundmaster to be handled in the main menu.
public class audiomaster : MonoBehaviour
{
public Slider volumeSlider;
public AudioSource audiosource;
public AudioClip defaultClip; //the default clip that will play at start up
void Start()
{
audiosource.clip = defaultClip;
audiosource.Play();
}
public void play(AudioClip clip1){
if (clip1.name == audiosource.clip.name && audiosource.isPlaying) { return; } //if were already playign the default clip
audiosource.clip = clip1;
audiosource.Play();
}
public void stop(){
if (defaultClip == audiosource.clip) { return; }
audiosource.clip = defaultClip;//when exiting trigger can revert to default audioclip
audiosource.Play();
}
void OnEnable()
{
//Register Slider Events
volumeSlider.onValueChanged.AddListener(delegate { changeVolume(volumeSlider.value); });
}
//Called when Slider is moved
void changeVolume(float sliderValue)
{
audiosource.volume = sliderValue;
}
void OnDisable()
{
//Un-Register Slider Events
volumeSlider.onValueChanged.RemoveAllListeners();
}
}
Variables for the slider and Default clip are assigned in the inspector as follows.