Question by
Bishok12 · Dec 09, 2018 at 09:20 PM ·
prefabsgameobjectsstaticinstances
Create 2 seperate instances of the same prefab,create 2 Separate instances of the same prefab
Hello Everyone,
I'm trying to create 2 separate instances of the keypad prefab below.
The problem is that it doesn't matter on which one of them I tap, they both respond and show the same output.
My guess is that they both refer to the same script attached to the prefab and I don't know how to create 2 separate instances of the same script.
Here the script attached to them:
using UnityEngine;
using UnityEngine.UI;
public class LockSystemScript : MonoBehaviour
{
public Text ScreenText;
private int _taps;
private Color _startColor;
private AudioSource _clickSound;
private RequestsManager _requestsManager;
private Vector3 _screenCenter;
private void Start ()
{
_taps = 0;
_startColor = ScreenText.color;
_clickSound = GetComponent<AudioSource>();
_requestsManager = RequestsManager.Instance;
_screenCenter = GetScreenCenter();
}
private void Update () {
if (Input.GetMouseButtonDown(0))
{
Ray ray = Camera.main.ScreenPointToRay(_screenCenter);
RaycastHit hit;
if (Physics.Raycast(ray, out hit, 100) && hit.transform.gameObject.tag.Equals("Button") && _taps <= 3)
{
ScreenText.text += hit.transform.name;
_clickSound.Play();
_taps++;
}
if (hit.transform.gameObject.tag.Equals("Submit"))
{
_clickSound.Play();
StartCoroutine(_requestsManager.InputCode(ScreenText.text, ScreenText));
}
if (hit.transform.gameObject.tag.Equals("Reset"))
{
_taps = 0;
ScreenText.color = _startColor;
ScreenText.text = "";
_clickSound.Play();
}
}
}
private Vector3 GetScreenCenter()
{
float screenX = Screen.width / 2;
float screenY = Screen.height / 2;
return new Vector3(screenX, screenY, 0);
}
}
keypads.png
(273.0 kB)
Comment
Your answer
Follow this Question
Related Questions
GameObject - SetActive not working 1 Answer
Resize Gameobjects based on screen size 0 Answers
Make an asset persist through scene changes without affecting other instances? 1 Answer
List of unused game objects and prefabs 1 Answer
How to transform many copies of a mesh object into many copies of same prefab? 0 Answers