pins are not visible after reset.
After re doing the animation and preventing the pinsetter from moving as per Ben video, all actions and animations are working as per script.
The issue is Pins are not visible after reset. The inspector shows they are there as per attached image. Now Ironically if I set swiper to “trigger” and then swiper moves through the pins and now you can see a new set of pins being set over top of original pins. so they are visible.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class PinSetter : MonoBehaviour {
public Text standingDisplay;
public GameObject pinSet;
public float distanceToRaise = 1f;
public float distanceToLower = -1f;
private bool ballOutOfPlay = false;
private int lastStandingCount = -1;
private int lastSettledCount = 10;
private float lastChangeTime;
ActionMaster actionMaster = new ActionMaster();
private Ball ball;
private Animator animator;
// Use this for initialization
void Start () {
ball = GameObject.FindObjectOfType<Ball> ();
animator = GetComponent<Animator> ();
}
void Update () {
standingDisplay.text = CountStanding ().ToString ();
if (ballOutOfPlay) {
UpdateStandingCountAndSettle();
}
}
public void SetBallOutOfPlay () {
ballOutOfPlay = true;
}
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 ResetPins () {
GameObject newPins = Instantiate (pinSet);
newPins.transform.position += new Vector3 (0, 20, 0);
}
void UpdateStandingCountAndSettle () {
// Update the standing count
// Call PinsHaveSettled() when they have
int currentStanding = CountStanding ();
if (currentStanding != lastStandingCount) {
lastChangeTime = Time.time;
lastStandingCount = currentStanding;
return;
}
float settleTime = 3f; //How ;long to settle time for pins settled
if ((Time.time - lastChangeTime) > settleTime) {
PinsHaveSettled();
}
}
void PinsHaveSettled () {
int standing = CountStanding ();
int pinFall = lastSettledCount - standing;
lastSettledCount = standing;
ActionMaster.Action action = actionMaster.Bowl (pinFall);
if (action == ActionMaster.Action.Tidy) {
animator.SetTrigger ("tidyTrigger");
Debug.Log ("Tidy");
} else if (action == ActionMaster.Action.EndTurn) {
animator.SetTrigger ("resetTrigger");
Debug.Log ("EndTurn");
} else if (action == ActionMaster.Action.Reset) {
animator.SetTrigger ("resetTrigger");
Debug.Log ("Reset");
} else if (action == ActionMaster.Action.EndGame) {
throw new UnityException ("Don't know how to handle this");
}
ball.Reset ();
lastStandingCount = -1;
ballOutOfPlay = false;
standingDisplay.color = Color.blue;
}
int CountStanding () {
int standing = 0;
foreach (Pin pin in GameObject.FindObjectsOfType<Pin>()){
if (pin.IsStanding()) {
standing++;
}
}
return standing;
}
}
Michael