It says there is an error in: Assets / Scripts / GamePlay.cs (123,17): error CS8025: Parsing error ¿How I can fix it?
using UnityEngine;
using System.Collections;
public class GamePlay : MonoBehaviour {
public GameObject[] petList;
public int maxPetCount = 40;
// An ArrayList for chained pet
private ArrayList chainedList;
// A place to keep all created pet to, easier management
private GameObject petHolder;
// Use this for initialization
void Start () {
// Create the place holder
petHolder = new GameObject ("Holder");
// Create the list
chainedList = new ArrayList();
// Move the pet creation to a function, so we can reuse it with
// spawning different number
Respawn (maxPetCount);
}
// Function to create pets
void Respawn (int count) {
for (int i=0; i<count; i++) {
GameObject instance = Instantiate (petList[Random.Range(0, petList.Length)], new Vector3 (Random.Range(-2.6f, 2.6f), 7.0f, -1.0f), Quaternion.identity) as GameObject;
// put the newly pet as the child of petHolder
instance.transform.SetParent(petHolder.transform);
}
}
// Update is called once per frame
void Update () {
if (Input.GetMouseButtonDown (0)) {
// simulate touch began
Vector3 p = Camera.main.ScreenToWorldPoint(Input.mousePosition);
RaycastHit2D hit = Physics2D.Raycast (p, Vector2.zero);
if (hit.collider != null) {
if (hit.collider.tag == "Pet") {
Pet pet = hit.collider.GetComponent<Pet> ();
// Add the pet to the chain
chainedList.Add (pet);
// Make it selected
pet.SetSelected (true);
}
}
}
if (Input.GetMouseButtonUp (0)) {
// simulate touch ended
// Only destroy pets in the chain with count > 2
if (chainedList.Count > 2) {
// Loop for every pet in the chain
foreach (Pet pet in chainedList) {
// Destroy it
Destroy (pet.gameObject);
}
// Call respawn function to generate new pets
Respawn (chainedList.Count);
} else {
// Chain count less than 3, just make the last pet unselected
SetChainedLastPetSelected (false);
}
// Clear the chain list
chainedList.Clear ();
}
if (Input.GetMouseButton (0) && chainedList.Count > 0) {
// simulate touch moved
Vector3 p = Camera.main.ScreenToWorldPoint(Input.mousePosition);
RaycastHit2D hit = Physics2D.Raycast (p, Vector2.zero);
if (hit.collider != null) {
if (hit.collider.tag == "Pet") {
Pet pet = hit.collider.GetComponent<Pet> ();
// Check if this pet already inside the chain?
if (!chainedList.Contains(pet)) {
// Not inside the chain, is it valid to be chained?
if (GetLastPetInChain ().Validate (pet)) {
// Yes, make the last chained pet unselected
SetChainedLastPetSelected (false);
// Add to the chain
chainedList.Add (pet);
// Make it selected
pet.SetSelected (true);
}
} else {
// This pet is inside our chain, what is the index?
int index = chainedList.LastIndexOf (pet);
// Second last?
if (index == chainedList.Count - 2) {
// Backward to second last pet, unselect the last pet
SetChainedLastPetSelected (false);
// Remove the last one
chainedList.RemoveAt(chainedList.Count-1);
// Make the last pet selected
SetChainedLastPetSelected (true);
}
}
}
}
}
// Process at every frame no matter there are pets in the chain
foreach (Pet pet in petHolder.GetComponentsInChildren<Pet>()) {
pet.SetHighlight (false);
}
// Highlight pet if there is a pet in the chain
if (chainedList.Count > 0) {
HighlightValidPet (GetLastPetInChain());
}