How to go about this?

Im creating an interior scene whereby users can click on objects to change color or textures.

The textuers portion is solved. but the problem start here.

i want to create something goes like this:-

awake function is hide cursor

1.right click to show cursor

2.mouseover to object, object is highlighted, gui options appear, also at the same time the screen is freezed

3.left click to select options (but how to create different options for different objects?)

4.after left click, user can go back to walk around..

Can anyone tell me how to go about with that? preferably to use only javasccript.

thanks

The language doesn't matter ;) i prefer C# but nearly everything can be done in both languages.

  1. Input.GetMouseButtonDown(1) is what you need to detect the right mouse button (0==left; 1==right 2== middle). To lock or unlock the cursor use Screen.lockCursor

  2. 3DObjects don't have events like mouseover, but you can use Physics.Raycast () in combination with Camera.main.ScreenPointToRay (Input.mousePosition); to get the object you're pointing at. I guess you use the FPSWalker script (or FPSController or how it's names now ;) ). To prevent moving you have to disable the script. Use GetComponent() to access your script and disable it.

  3. Here you have to be a bit more precice what kind of GUI you need, how many different objects/GUIs you have/need.

  4. Inside one of your GUI.Button() just repeat what i mentioned in 2. Use GetComponent() to access your script and enable it. And lock the cursor again.

*Edit*14.01@03:29

Well if you want a complete different GUI for each object i would use a strategy pattern to offer a common interface. That's quite advanced stuff for a beginner but a basic "tool" in oop. ;) I'm not that deep into Javascript so it's difficult to show you an example in JS but i try:

That's a simple "base class". Every Object have to be derived from this class in order to be able to get selected:

class SelectableObject extends MonoBehaviour
{
   // static var to hold the current selected object
   public static var m_CurrentSelected : SelectableObject = null;
   // define common vars or functions here
   public var Health : float = 100.0f;
}

Here is an example of one of your object scripts:

class Object1 extends SelectableObject
{
   function Update (){
      //Do normal stuff related to your object
   }
   function OnGUI(){
      // check if we are selected, if not, return
      if (m_CurrentSelected != this)
         return;
      // Draw Your GUI for this object here
      if (GUILayout.Button("deselect")) {
         SelectableObject.m_CurrentSelected = null;
      }
   }
}

with this little "trick" you can select an object by it's script component.

Just assign the object you hit with your ray to SelectableObject.m_CurrentSelected

That function is your "picker" script and should be attached to maincamera

function Update() {
   if (Input.GetMouseButtonDown(1)) {
      var ray = Camera.main.ScreenPointToRay (Input.mousePosition);
      var hit : RaycastHit;
      if (Physics.Raycast (ray, hit, 100)) {
         var obj = hit.collider.GetComponent(SelectableObject);
         if (obj != null) {
            SelectableObject.m_CurrentSelected = obj;
         }
      }
   }
}

One last important hint: the script filename and the class name have to be the same. In C# you always have to do that, in JS you don't need to define the class but in that case we want a different base class (in Unity classes have to be derived from MonoBehaviour to be able to attach it to a GameObject)

Good luck! It's not easy stuff for beginners, but everyone have to start somewhere ;)

It needn't be quite as complex as the other answer, here is some pseudocode to get you started:

awake function is hide cursor

Screen.lockCursor = true;

1.right click to show cursor

Screen.lockCursor = false;

2.mouseover to object, object is highlighted, gui options appear, also at the same time the screen is freezed

some variable such as:

var showGUI : boolean = false;

inside OnMouseEnter() change to highlight material, showGUI = true; Time.timeScale = 0;

inside OnMouseExit() change to default material, showGUI = false; Time.timeScale = 1;

function OnGUI()
{
    if(showGUI)
    {
        // display gui
    }
}

3.left click to select options (but how to create different options for different objects?)

This kind of polymorphic behaviour is non-trivial. The other answer touches on this stuff.

4.after left click, user can go back to walk around..