I’m new in Unity gaming and making android game. I am implementing the menu screens before the game starts. I have a 15 objects on the screen that can be clicked to select the players i want in my game.
to touch the object i have separate script for each object, and I add that player name in my List when clicked. The problem is that if I click my object once, and then check the size of my List, it gives either 5 or 4 or even more than that. Is it because my Update() method is being called more than once? Please tell me what to do?
My script is as follows:
using UnityEngine;
using System.Collections;
public class midge : MonoBehaviour {
// Use this for initialization
void Start () {
}
void Update () {
if (Input.touchCount == 1)
{
Vector3 wp = Camera.main.ScreenToWorldPoint(Input.GetTouch(0).position);
Vector2 touchPos = new Vector2(wp.x, wp.y);
if (collider2D == Physics2D.OverlapPoint(touchPos))
{
Material newMat = Resources.Load("New Material", typeof(Material)) as Material;
gameObject.renderer.material = newMat;
PlayersManager.objPlayerList.Add(PlayersManager.setPlayerObject("Midge"));
countausplayer.countteam++;
}
}
}
}
Please guide me where am I going wrong?? It’s really urgent!!