Scripts / E to interact to a model

Author
Message
Matteo99x
User Offline
Joined: 1st Jul 2024
Location:
Posted: 1st Jul 2024 15:54
Hi i'm new on GameGuru, i want to know how i can make a text "PRESS E TO INTERACT or something like that" on a Model and after the player press it, the model disappear, how i can do something like that? Can you help me please?
PM
Matteo99x
User Offline
Joined: 1st Jul 2024
Location:
Posted: 2nd Jul 2024 13:17
I make the text, now i have to understand how to make the model disappear when press "E" and how to make another model spawn in the same place... i'm starting with that

if GetScancode() == 18
Spawn Soldier
PM
telephonehymn
User Offline
Joined: 17th Jul 2024
Location:
Posted: 17th Jul 2024 05:40 Edited at: 13th Aug 2024 09:33
I have the code for your reference
using UnityEngine;
using UnityEngine.UI;

public class InteractableObject : MonoBehaviour
{
public Text interactText; // Assign the UI Text element in the Inspector

void Start()
{
interactText.gameObject.SetActive(false); // Hide the text initially
}

void Update()
{
if (Input.GetKeyDown(KeyCode.E))
{
RaycastHit hit;
if (Physics.Raycast(Camera.main.transform.position, Camera.main.transform.forward, out hit, 5f))
{
if (hit.transform == transform)
{
interactText.gameObject.SetActive(false); // Hide text after interaction
gameObject.SetActive(false); // Hide the model
}
}
}
}

void OnTriggerEnter(Collider other)
{
if (other.CompareTag("Player"))
{
interactText.gameObject.SetActive(true); // Show the text when the player is near
}
}

void OnTriggerExit(Collider other)
{
if (other.CompareTag("Player"))
{
interactText.gameObject.SetActive(false); // Hide the text when the player leaves
}
}
}
boxing random
gentleanarchist
User Offline
Joined: 23rd Jul 2024
Location:
Posted: 23rd Jul 2024 02:54
To create an interactive model in a game where a text like "PRESS E TO INTERACT" appears, and upon pressing the key the model disappears, you can use a game development platform like Unity or Unreal Engine.
Northern
14
Years of Service
User Offline
Joined: 5th Nov 2010
Location: Brazil
Posted: 9th Aug 2024 23:32
@Matteo99x and all,

The programming code used in game engines such as Unity (C#, JavaScript or Boo programming, depending on the year of the version you are using) or Unreal Engine (basically, it uses C++ programming).

However, GameGuru Classic Engine uses Lua script programming. Therefore, I'm sorry to say, but the examples of scripts written for Unity or Unreal Engine, shown above, will not work at all in GameGuru Classic for what you want to do.

To do what you want, it is not a very easy task for someone who is just starting with GameGuru Classic programming, especially spawning a new object in the same place, where another one disappeared.

To make any object disappear or appear is relatively easy, see the example below :

function hidemyobj_init(e)

Show(e);

end -- Do not remove it

function hidemyobj_main(e)

e_Key = g_Scancode;

-- e_Key for E key = 18; therefore:

if e_Key==18 then
Hide(e);
end

-- To show up the object again, click on Y key = 21; therefore

if e_Key==21 then
Show(e);
end


end -- Do not remove it

Now, save the script above with the name hidemyobj.lua in the GameGuru Classic scriptbank directory (folder). Run GameGuru Classic, and click on add new entity icon.

In Barrels, click on Barrel (Clean) and then on OK.

Place it somewhere in the terrain. Left-click on the barrel (clean) and then on properties. In the AI ​​System Main field.

A small rectangle or square with three dots will appear.

Click on the small square mentioned, and look for the script above, called hidemyobj.lua.

Then, click on the Apply Changes button. After returning to the terrain editor, click on the Player Start icon and place it near the barrel.

So, click on the button with a rocket (Test Game) in the icon bar and test the Lua script above.

A final reminder: the name of a script in GameGuru Classic is always lowercase, remember that.

That's all.
Cheers,
-Northern

PM
fabrieno80
2
Years of Service
User Offline
Joined: 5th Feb 2022
Location:
Posted: 26th Sep 2024 22:22 Edited at: 13th Dec 2024 15:26
What I do is whenever the character moves or the camera rotates, I do a raycast from the camera and check if I hit anything. If it hits an object I check if it implements my InteractableInterface and if so I display the message in the UI. If it hits nothing then I clear the message and clean up.



https://tutuapp.uno https://9apps.ooo/
PM

Login to post a reply

Server time is: 2024-12-21 13:13:57
Your offset time is: 2024-12-21 13:13:57