Ostap_Gordon Posted July 5, 2021 Share Posted July 5, 2021 (edited) Hello friends, can you help me with writing a simple script? Because something doesn't work at all The task is as follows. This is necessary so that when you click (with a valid left mouse button (we are talking about an FPS controller) on a specific object, something happens (something, for example, node.Enabled = false)Like a light switch Edited July 5, 2021 by Ostap_Gordon Link to comment
arzezniczak Posted July 5, 2021 Share Posted July 5, 2021 You can use intersections to detect mouse clicks on specific object. You can use masks to detect intersections with interesting you objects.https://developer.unigine.com/en/docs/2.14.1/code/usage/intersections/index?rlang=cshttps://developer.unigine.com/en/docs/2.14.1/api/library/engine/class.world?rlang=cs#getIntersection_Vec3_Vec3_int_Object Link to comment
cash-metall Posted July 6, 2021 Share Posted July 6, 2021 https://developer.unigine.com/en/docs/2.14.1/api/library/worlds/class.worldintersection?rlang=cs#usage_example /* ... */ // initialize points of the mouse direction Vec3 p0,p1; // get the current player (camera) Player player = Game.Player; if (player == null) return 0; // get width and height of the current application window int width = App.getWidth(); int height = App.getHeight(); // get the current X and Y coordinates of the mouse pointer int mouse_x = App.getMouseX(); int mouse_y = App.getMouseY(); // get the mouse direction from the player's position (p0) to the mouse cursor pointer (p1) player.getDirectionFromScreen(out p0, out p1, mouse_x, mouse_y, width, height); // create an instance of the WorldIntersection class to get the result WorldIntersection intersection = new WorldIntersection(); // create an instance for intersected object and check the intersection Unigine.Object obj = World.GetIntersection(p0,p1,1,intersection); // if the intersection has been occurred, change the parameter of the object's material if(obj != null) { for (int i = 0; i < obj.NumSurfaces; i++) { obj.setMaterialParameterFloat4("albedo_color", new vec4(1.0f, 0.0f, 0.0f, 1.0f),i); // show intersection details in console Log.Message("point: ({0} {1} {2}) index: {3} \n", intersection.Point.x, intersection.Point.y, intersection.Point.z, intersection.Index); } } 1 Link to comment
Recommended Posts