This question was 
             closed Dec 05, 2015 at 07:06 PM by 
             GreenTraveler for the following reason: 
             
 
            The question is answered, right answer was accepted
 
               Question by 
               GreenTraveler · Dec 05, 2015 at 06:04 PM · 
                c#instantiatebutton  
              
 
              scroll rect UI buttons all do the same thing
i can get one button to work the way it should but all the other buttons do the same exact thing would someone please help
 using System.Collections;
 using System.Collections.Generic;
 using System;
 using UnityEngine.UI;
 
 
 public class ButtonList : MonoBehaviour 
 {
     public GameObject spawnPoint;
     private float lastClick = 0;
     public GameObject prefabButton;
     public RectTransform ParentPanel;
     private int dogNo = 0;
 
     void Start () 
     {
         
         for(int i = 0; i < DogHouse.control.myDogs.Count; i++)
         {
             
             GameObject goButton = (GameObject)Instantiate(prefabButton);
             
             goButton.transform.SetParent(ParentPanel, false);
             goButton.transform.localScale = new Vector3(1, 1, 1);
             goButton.transform.GetChild(0).GetComponentInChildren<Text>().text = DogHouse.control.myDogs[i].gameObject.name;
             goButton.name = "DogButton-" + dogNo.ToString();
             dogNo ++;
              
 
             Button tempButton = goButton.GetComponent<Button>();
             int tempInt = i;
             
 
             tempButton.onClick.AddListener(() => Selection0(tempInt));
             tempButton.onClick.AddListener(() => Selection1(tempInt));
         }
         
         
     }
     
 
             
         
 
 
     public void Selection0 (int tempInt ) 
     {
         {
             if (lastClick > (Time.time - 1f)) return  ;
             lastClick = Time.time;
             Instantiate(DogHouse.control.myDogs[0], spawnPoint.transform.position, Quaternion.identity);
             GameObject.FindWithTag("Player").GetComponent<Animation> ().Play ("Run");
             GameObject.FindWithTag("Player").gameObject.GetComponent<SpeedForce>().enabled = true;
             DogHouse.control.playerDog = 0;
         }
     }
 
     public void Selection1 (int tempInt) 
     {
         {
             if (lastClick > (Time.time - 1f))
                 return;
             lastClick = Time.time;
             Instantiate (DogHouse.control.myDogs [1], spawnPoint.transform.position, Quaternion.identity);
             GameObject.FindWithTag ("Player").GetComponent<Animation> ().Play ("Run");
             GameObject.FindWithTag ("Player").gameObject.GetComponent<SpeedForce> ().enabled = true;
             
             DogHouse.control.playerDog = 1;
         }
     }
 
 }
 
              
               Comment
              
 
               
              never$$anonymous$$d fixed it with
       if (tempInt == 0)
     {
     }
     if (tempInt == 1)
     {
     }