- Home /
How to select one prefab from more ?
I'm developing one simple game. I'm beginner of Unity.
I have three character in my scene. What I want to do is, when I click on one character , only that will move using keyboard input other two will stand idle. and so on.
Any suggestion is helpful.
I used following code using which i can able to select one character from mouse. How can I do same for all? Also, I want to move focus of camera to selected prefab.
 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class raycast : MonoBehaviour {
 
     // Use this for initialization
     void Start () {
         
     }
 
     // Update is called once per frame
     void Update()
     {
         if (Input.GetMouseButtonDown(0))
         {
             Debug.Log("Mouse is down");
 
             RaycastHit hitInfo = new RaycastHit();
             bool hit = Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hitInfo);
             if (hit)
             {
                 Debug.Log("Hit " + hitInfo.transform.gameObject.name);
                 if (hitInfo.transform.gameObject.tag == "Himalaya")
                 {
                     Debug.Log("It's working!");
                 }
                 else
                 {
                     Debug.Log("nopz");
                 }
             }
             else
             {
                 Debug.Log("No hit");
             }
             Debug.Log("Mouse is down");
         }
     }
 }
 
You could add bool for each character controller you have if they are selected then you can move them.
There was a solution to the camera though I forgot where it was. Try searching in google keeping objects in camera viewport.
Just a note on your class. Avoid using similar/existing class name built in unity. else you might get confused. You could make use of namespace if you want to keep that class name.
Your answer
 
 
              koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                