unity3d: how to use OpenFolderPanel - unity3d

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.

Related

No function dropdown in AnimationEvent in Unity

I try to handle some events during animations, but everywhere I look, every tutorial have access to AnimatorEvent Inspector like this:
A nice simple field, where you can select a function, I want this!
But instead of this, I always getting this sick 5 fields view, and don't have any idea how to handle animation event in this case!
I tried to create function test() with debug log, but it didn't work anyway. Why I can't get access to this simple window where I can choose an function?
You will need to add this animation into a State in Animator Controller (via Animator Window).
In the object which contains Animator component, attach your script component to it.
Open the Animation window, select the object above, you will see a dropdown of animations (top left) which Animator Controller of this object contains. Choose and add event to the animation you want to.
Select the event in Animation Window, in the Inspector, you should see the dropdown of public functions of your script component attached above.
Answer by Aluminium18
Sometimes it doesn't work even if you do all things according to tutorials or advices in internet. I often leave Unity editor launched for a long time without any interactions with it. After several gibernations and several days it can get buggy - various errors appear, you can't see some functions from scripts and so on. So, just reloading the Unity editor solves many of such issues for me. And it continues to happen so for several years no matter what Unity version you have. I tried versions from 2019.x.x to 2022.x.x - all this time Unity behaves itself the same.

CS-Script doesn't show up in Add Component search?

I'm using Unity 2020.1.1f1, when I try to add a Component to a GameObject, the component that I search for does not show up for me to add it? The component I have is located in a sub folder of Assets. Should I have imported it elsewhere? I have also restarted Unity to see if it would refresh.
Short answer: It should derives from MonoBehaviour
Looks like there is a thread on this already, I'll close this with the link: Can't add script component because the script class cannot be found?

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()

how can i regist my own property to unity native animator?

I want to edit some custom proeprty of my own script, 'TopazObject' in Unity native system. But it doesn't appear to animation window.
If the property is public then it is going to show up in the animation tab. Make sure its public. If you have a variable. If you want a variable with a custom class type to be visible there I think there is no way to do it.

Inspector variable for selecting a function to be called (Unity3D)

The latest versions of NGUI have this great tool that lets you pick which function within any of the target's scripts will be called when you click on it.
Basically, it's a select box within the inspector that gets automatically filled with all the functions from all the scripts attached to the game object.
How can I generate a function list that fills up automatically like this?
I don't want to have to maintain an enum with all the possible functions (including some that the current object might not have)
I tried looking at the code NGUI used, but it was a bit too complicated for me to understand right now.
If you want to do it like in NGUI then use the tools that are available within NGUI itself and define a public variable like this:
public List<EventDelegate> DelegateList = new List<EventDelegate>();
With this, you can drop MonoBehaviour scripts in the Inspector field and can then select public methods/delegates contained in that script.
You can then invoke them like this:
void Start() {
EventDelegate.Execute(DelegateList);
}
Now every method in your delegate list will be invoked. You can see this for example in the UIButton script where this is used to handle the OnClick delegates.