After hitting start game…
Console shows that Spawn gets called 4 times.
Notice how the numbers are in the console as well.
In this case I used the new Bow as default weapon (please note: looks good after placing in hand)
Unchecked isRightHanded…
Seems call one is good it shows false great
then it gets called again and is still false: notice the 2
then it gets called 3 and 4 both true…
box ends up in right hand upside down and not right…
I have been trying to find out where else on game start Spawn gets called and changes the bool on its own…
Here is a screen shot of Bow SO
and finally the code for Spawn is within this Weapon.cs below
using UnityEngine;
namespace RPG.Combat
{
[CreateAssetMenu(fileName = "Weapon", menuName = "Weapons/Make New Weapon", order = 0)]
public class Weapon : ScriptableObject
{
[SerializeField] AnimatorOverrideController animatorOverride = null;
[SerializeField] GameObject equippedPrefab = null;
[SerializeField] float weaponRange = 2f;
[SerializeField] float weaponDamage = 10f;
[SerializeField] bool isRightHanded = true;
int timesCalled = 0;
public float GetWeaponRange()
{
return weaponRange;
}
public float GetWeaponDamage()
{
return weaponDamage;
}
public void Spawn(Transform rightHand, Transform leftHand, Animator animator)
{
timesCalled += 1;
Debug.Log(timesCalled + " Spawning... isRightHanded is: " + isRightHanded);
if(equippedPrefab != null)
{
Transform handTranform;
if(isRightHanded)
{
handTranform = rightHand;
}
else
{
handTranform = leftHand;
}
Instantiate(equippedPrefab, rightHand);
}
//Animator animator = GetComponent<Animator>();
if(animatorOverride != null)
{
animator.runtimeAnimatorController = animatorOverride;
}
}
}
}
Thanks for any help!