Hi everybody
I´m making an app that uses several prefabs in the same scene. I´ve been looking the way to resize only one prefab when click two times on it, but I didn´t found it. I want resize the prefab when we make click two times on it, and meanwhile hide the others prefabs. With my actually script on the prefab when we click two times, all the prefabs change its size:
first up, lets correct some terminology. Prefabs are held in the project folder and are templates, when they are used to put something into a scene (either through code or in the editor) they become instances of that prefab. Basically you can’t “click” on a prefab because it doesn’t exist in the scene.
secondly, please use [code ][/code ] tags when pasting code into the forums, really helps with the readability, add line numbers (useful in conjunction with full error messages) etc. there is a sticky on them at the top of the scripting forum.
thirdly, in your code there isn’t anything to check what is being clicked on. So all your instances respond when the left mouse button is clicked. You’ll either need to add in a raycast, or work with the OnMouseOver function
Thanks for your answer, and sorry about my newbie mistakes.True, in the code there isn´t anything to check what is being clicked on, and that is what I looking for. I know with this code the changes will be apply in all prefabs instances I have, because I´m not able to point what is the prefab instance clicked. How can I use raycast to do this?
Thanks!!
Ok, I try to explain myself better. My mobile app have a scene in which there are 4 prefab instances (everyone is a quad with a image on it), created vertically. To see every instance I have to move up and down my camera with screen touch. What I want is resize one of the prefab instance when clicked two times on it. Some points in my app:
I´ve created a script and added to my prefab (I show it later)
I´ve putted every prefab instance in a GameObject array when everyone is created
Is 2d not 3d
The main camera is Orthographic
In the script added to the prefab I tried to use a Raycast but it doesn´t work:
void Update () {
if(Input.GetMouseButtonDown(0))
{
if(Time.time-lastClickTime<catchTime)
{
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit hit;
if(Physics.Raycast(ray,out hit))
{
if(hit.collider.gameObject.name==CreadorQuads2.instances[0].name)
CreadorQuads2.instancias[0].transform.localScale= new Vector3(600,1200,0.8f);
}
}
}
In this case CreadorQuads2 is the script where I create the prefab intances, and I show it only for one (instances[0])
If someone can help me, I really apreciate it.
Thanks a lot in anvanced!!