hey guys …i’m trying the wiring of the script with the animations …but after each ball everything i got is tidy and “reset” is not working at all …but in console i got “Parameter “EndTurn” doesn’t exist” …so any idea ??? When i try “reset” using the button it works fine but i can’t make it work by script and i’m sure of its trigger’s name spelling…so i’m really stuck in here…this is my code:
public class PinSetter : MonoBehaviour {
public int lastStandingCount = -1;
public Text standingDisplay;
public GameObject pinsForm;
private float lastChangeTime;
private bool ballEnteredBox;
private Ball ball;
private int lastSettledCount = 10;
private ActionMaster actionMaster =new ActionMaster();
private Animator ani;
void Start () {
ball = GameObject.FindObjectOfType<Ball>();
ani = GetComponent<Animator>();
}
// Update is called once per frame
void Update () {
standingDisplay.text = CountStanding().ToString();
if (ballEnteredBox)
{
CheckStanding();
}
}
int CountStanding()
{
int standing = 0;
foreach (Pin pin in GameObject.FindObjectsOfType<Pin>())
{
if (pin.IsStanding())
{
standing++;
}
}
return standing;
}
public void CheckStanding()
{
int currentStanding = CountStanding();
if(currentStanding!= lastStandingCount)
{
lastChangeTime = Time.time;
lastStandingCount = currentStanding;
return;
}
float settleTime = 3f;
if((Time.time - lastChangeTime) > settleTime)
{
PinHaveSattled();
}
}
void PinHaveSattled()
{
int standing = CountStanding();
int pinFall = lastSettledCount - standing;
lastSettledCount = standing;
ActionMaster.Action action = actionMaster.Bowl(pinFall);
if(action == ActionMaster.Action.Tidy)
{
ani.SetTrigger("Tidy Trigger");
}
else if (action == ActionMaster.Action.Reset)
{
ani.SetTrigger("Reset Trigger");
lastSettledCount = 10;
}
else if(action == ActionMaster.Action.EndTurn)
{
ani.SetTrigger("Reset Trigger");
lastSettledCount = 10;
}
else if (action == ActionMaster.Action.EndGame)
{
throw new UnityException("Dont know How To EndGame yet");
}
ball.ResetTheBall();
lastStandingCount = -1;//indicates pins has settled and ball not back to box
ballEnteredBox = false;
standingDisplay.color = Color.green;
ani.SetTrigger(actionMaster.Bowl(pinFall).ToString());
}
void OnTriggerExit(Collider other)
{
GameObject thingLeft = other.gameObject;
if (thingLeft.GetComponent<Pin>()){
Destroy(thingLeft);
}
}
void OnTriggerEnter(Collider col)
{
GameObject thingHit = col.gameObject;
//Ball enters Play box
if (thingHit.GetComponent<Ball>())
{
ballEnteredBox = true;
standingDisplay.color = Color.red;
}
}
public void RaisePins()
{
foreach (Pin pin in GameObject.FindObjectsOfType<Pin>())
{
pin.RaiseIfStanding();
}
}
public void LowerPins()
{
foreach (Pin pin in GameObject.FindObjectsOfType<Pin>())
{
pin.Lower();
}
}
public void RenewPins()
{
Instantiate(pinsForm, new Vector3(0,0,1829), Quaternion.identity);
}
}