Roblox part appearing when clicked on another part - roblox

I need help, I have an idea for a game but one of the main mechanics does not work. I need when you click a part another part appears

Roblox part appearing when clicked on another part
You can detect when a player clicks the part by putting a ClickDetector inside of it, then a ServerScript in that same part which will have a variable that points to the ClickDetector, using the ClickDetector's MouseClick detect, you can use a :Connect() to create a new Instance("Part") in Workspace.
Example
Hierarchy
Workspace
Terrain
Camera
Part
Script
ClickDetector
Script
local clickdetector = script.Parent.ClickDetector
clickdetector.MouseClick:Connect(function())
...
local newPart = Instance.new("Part")
newPart.Parent = workspace
...
end)
I hope this helped, you should research the ClickDetector and Instance API references on the ROBLOX DevHub. Just keep in mind, if you don't give the new part a CFrame it will spawn at 0,0 in the world.

Related

After updating Unity, a second EventSystem is created on Run

I just updated from Unity 2019.3.13f1 to 2021.3.6f1 mid project. Not ideal I know, but I was advised to by Unity Support in order to add the IAP package. After the update, on running my launch scene, I get this error:
There are 2 event systems in the scene. Please ensure there is always exactly one event system in the scene
It turns out, a second EventSystem object is being created on running, which hadn't been the case before the update. At first, I just disabled the one in the hierarchy, which solved the problem as the second EventSystem then didn't conflict. However, when the game goes to a second scene and then returns to the initial scene, the duplicate EventSystem is not created, meaning that the menus don't get any input!
Can anyone advise?
This forum post (https://forum.unity.com/threads/upgrade-to-2020-lts-creating-duplicate-eventsystem.1098133/) detailed the same problem.
I have tracked this down to calling Advertisement.Initialize. If I
call that while running in the Editor; then it creates a new
EventSystem. I am not sure why. It doesn't seem to matter if I pass
true or false for the testMode value.
The poster there solved it by surrounding the Initialising line with #if !UNITY_EDITOR. However I wanted to be able to see the adverts testing in the editor - so I added this code, after Advertisement.Initialize(_gameId, _testMode, this):
var es = FindObjectsOfType<EventSystem>();
if (es.Length > 1)
{
for (int i = 1; i < es.Length; i++)
{
Destroy(es[i].gameObject);
}
}
This seems to have fixed the problem.

Unity Visual Scripting Variable

I have a scene that has 3 buttons, one for each level. I made buttons 2 and 3 uninteractable and I want to make it so when you win the 1st you can start the 2nd etc... So I have unchecked the interactable box from the options of button2. Then I went to the script of my player and I have connected the following parts so when he completes the 1st level the button 2 gets to be interactible. But there seems to be an issue.
(This answer only applies if you were loading new scenes.)
Perhaps, the problem is that you can’t save a variable telling which levels are allowed. (Unless you do it through, an actual save mechanic.) this is because unity destroys all objects in a scene when loading a new scene. This removes all data stored in variables. You could get around this from using
DontDestroyOnLoad(gameObject);
this saves the gameObect variable you put in the parentheses through scene loading. You can attach a script that would store the variables to this, to save information.
If you can’t figure out how to get the variables from other scripts, use this:
var newVariable = GameObjectVariable.GetComponent<scriptName>().variableName;
I see you were using visual coding, so if you can try and figure out how to find these methods in there, it should work.
If you want to use actual save mechanics, go to this link:
https://docs.unity3d.com/ScriptReference/PlayerPrefs.html/
Set Variable need to receive a flow input.

Unity 3D First Person Controller Script Reference

The FPS Controller Script can be found in Unity Standard Assets folder under Characters/FirstPersonCharacters. I added it to an object called Player. And when I want to pause the game (I've done a pause menu UI), I don't like that it still follows the mouse on the screen, so I want to freeze that rotation. Since I use the free rigidbody version, the RigidbodyConstrains does not work. I need to get a reference to that script to write .enabled = false; But it does not work, the Unity does not recognize it. I wrote:
GameObject.FindGameObjectWithTag("Player").GetComponent<FirstPersonController>().enabled = false;
But it does not work, even if I import UnityStandardAssets(I mean in the script: using UnityStandardAssets;)
I've tried a lot of other solutions, but I can't find the right one! Could you please help me? Thanks in advance!
vs2019error_image
inspector view
i have tested in my visualstudio 2017 i have to add that line:
using UnityStandardAssets.Characters.FirstPerson;
so i have taken the script directly from folder standard Asset
if you see into the script you have this line:
namespace UnityStandardAssets.Characters.FirstPerson
you have to precise the path where to find the class
this line is proposed by VisualStudio 2017, dunno why not by visual studio 2019
For anyone else in the future coming across this, the current firstpersoncontroller script only requires that you add
using StarterAssets;
and then you can use GetComponent()

Should I add the information in both side

I am new to unity ,plz forgive me asking these questions
It bumps out : default reference will only be applied in edit mode
Is it important, what is that?
Should I need to add the information(food and border ) to both sides?
The second image are default references. If you set them they are automatically applied after adding this script to an object.
They are not required. And only apply to a script added via the Editor (not by script!). What matters later on runtime are only the values on the GameObject.
Further you can only reference assets from the Assets folder here. They make sense e.g. if you have a button script that uses a certain Click sound, a texture and e.g. a prefab. For these three you now could already define default values so someone using your component doesn't have to assign everything everytime but already has the default references as a kind of fallback.
So in your case it would only make sense, if the borders are prefabs from the Assets that are spawned by this script. The FoodPrefab is even called like this and makes sense to have as a default reference so you don't have to drag it into each and every instance of SpawnFood you create.
And btw just by looking at your settings you should probably directly make your fields of type RectTransform so you can't accidentally reference another object there.

unity3d: how to use OpenFolderPanel

I'm new to unity. I want to try this tutorial but I failed.
I created a GameObject - UI - Button, and tried to add script to Canvas. But I got this error. Any help would be appreciated.
OpenFolderPanel is an Editor script which lets people to make some customized function for Unity Efitor.
If you want to click button to show file dialog in your game, you can try StandaloneFileBrowser
Alright, I know your mistake. When you create a c# script, do as follows (if you want to attach it to a gameobject).
1) Select the gameobject in the heirarchy.
2) Click add component in the inspector window.
3) Type in the name of your new script, and Unity will generate a basic script derived from MonoBehaviour automatically.
BTW, game objects have monobehaviour derived scripts on them (in singleplayer). The script you are using is derived from EditorWindow, not MonoBehaviour. Personally, I have not used a custom editor, but I think the script you are using should work automatically without having to attach it to a gameobject.