Finding Main Camera in CustomUnityEditor Class - c#

Iam writing a custom editor script in unity. I want to find the MainCamera in the scene for Custom Editor class so it can be directly assigned to the script and I dont have to assign it. I know i can find all cameras in scene and iterate over it through tags but I want to know if weather a direct method like Camera.main is available which brings the MainCamera of the scene in Custom Editor.
PS: I know it is easy to assign directly but still I want to do it by fetching through in custom editor script. Also I dont want to do it at runtime in start as I have some canvas related calculations which needs to be taken care of

OK I know this is embarrassing but here is the answer which was really simple.
You can directly use the code below to get the main camera.
GameObject.FindGameObjectWithTag("MainCamera").GetComponent<Camera>();
Note:
This will find the first camera with tag like so if your scene has only one main camera then it will get you that and don't have to worry about Camera.main. But my second part of question still remains. When is the Camera.main is assigned?

Related

How to use Humanoid Model : Animator(property) in scripts using Unity Scriptable API

I'm newbie at unity animations and stuff and I want to create a game scene in which at run time I would be able to move a humanoid 3D model and save the movement as an animation (.anim) file.
I may move the parts of the model by mouse or by mapping scrolling bars to animation property values, somehow.
To do all this I decided to go for the animators (properties) of a model. Kindly look at the picture in the link below to know exactly what I am talking about. (Wasn't able to post image since I'm new to stack overflow too)
I searched the unity Scriptable API for this but wasn't able to find the documentation on how to use the above mentioned property directly in your scripts so that animation curves can be generated from them.
Is it possible to do this?
Is there a better way to record animations of humanoid models at runtime (in-game mode) or a better property for humanoid models to use?
Note: The whole animation process is to be handled through code.

Ignore Default Gravity In Pipeline - Unity

Forgive me if there is already another post addressing something like this, but I haven't found it yet. I'm trying to get my object to ignore the default gravity field and move between the walls of the pipe in the image below:
The effect I'm trying to achieve is to allow my player (cube) to exit with a different rotation/spin when leaving the pipe as it falls back toward the ground.
I've seen an attractor script for planetary bodies elsewhere, but I'm not sure those apply to this scenario or not. Obviously, I'm planning on using a mesh collidor for my pipeline in the image (I created this in Blender) and the faces are inverted.
If I need to create a script for this, where would I start? Which object would I apply this script to and in which way?

DontDestroyOnLoad - how to destroy?

I'm working on a Vuforia (legacy) application.
In "Play" mode in Unity I can see that some "DontDestroyOnLoad" content is being generated, (looks like it's sort of a camera).
This might be a reason of why I have some problems when switching between the scenes, so the question is how to make these elements "destroyable"?
'DontDestroyOnLoad' It means that they won't manage it automatically. so if you want to destroy it, you should destroy manually like
GameObject.Destroy(GameObject.Find("TextureBufferCamera"));

Getting Movement with Google Cardboard in Unity

I want to put a scene in Unity into virtual reality using Google Cardboard.
I used to be able to just drag a CardboardMain prefab into the scene, delete the main camera, use CardboardMain as the camera position, and CardboardHead to track where the user was looking.
After reading the release notes for the new updates, I thought I could drag a GVREditorEmulator and GVRControllerMain into the scene, and keep the normal camera.
Unfortunately, I can't figure out how to get the camera to follow my character with this new setup. (In this case, a rolling ball.)
If I change the position of the normal camera, it looks like it works fine in Unity, but as soon as I upload it to my phone, the user stays in the same place, while the ball rolls away. (The user can still control the ball's movements, but the camera/user doesn't follow the ball at all.)
I had thought that the chase cam demo would be useful, but that's only for Daydream, and I'm using Cardboard.
This trick seemed to work for some people. I tried in on a previous version of Unity and a previous version of the SDK and it did not seem to work. I may just need to try it on this new version, but I'm worried about going into the released code and editing it, so I'd prefer answers that don't require this.
Is there any way I can get the user to move in a Google Cardboard scene in Unity when I upload it to my iPhone?
UPDATE:
It looks as though my main camera object is not moving, making me think that something is resetting it back to the center every time, lending some more credence to the "trick" earlier. I will now try "the trick" to see if it works.
UPDATE: It doesn't look like the lines listed in the "trick" are there anymore, and the ones that are similar in the new program don't even seem to be running. Still trying to figure out what continues to reset the main camera's position.
UPDATE: Just got a response back from Google on GitHub (or at least someone working on the SDK) that says "You just need to make the node that follows the player a parent of the camera, not the same game object as the camera." I'm not exactly sure what that means, so if someone could explain that, that would most likely solve my problem. If I figure it out on my own I'll post back here.
UPDATE: Zarko Ristic posted an answer that explained what this was, but unfortunately the tracking is still off. I found out how to get Google Cardboard to work with the old SDK and posted an answer on that. Still looking for ways to get the new SDK to follow a character properly.
You can't change positioin of camera in cardboard application, position of MainCamera it always must be 0,0,0. But you can just simply made empty GameObject and make it parent of MainCamera. In Cardboard games actualy you can move parent of camera instead MainCamera directly.
Add script for tracking ball to MainCamera parent (GameObject).
This does not answer my question, but is a solution to the problem.
Do not use the newest version of the SDK. Use version 0.6
When building the app in Unity, do not select to have VR enabled under the build settings. (VR will still be enabled in the app.) (Credit: Zarko Ristic)
When putting the app onto your phone, if XCode prompts you to change any settings, you can ignore it.
In addition, disable bitcode under "Build Settings -> Enable Bitcode -> No" (Currently, this will not allow you to put your app onto the app store. I would greatly appreciate it if anyone has information on how to get it to run without doing this.)
Now your app should run on your phone correctly.

How to use Unity Scripting with Vuforia

This maybe a stupid question but this keeps moving in my mind.
here's the situation.
I have a small application deployed in Hololens and using vuforia extensions, I'm able to track and recognize a real 3d object. I'm able to make holograms appear too, as long as holograms are children of the target object.
What I want to do is to activate or deactivate holograms that is not a child of the target object. I can't do it through code since the script i'm manipulating is a name space.
I tried putting methods inside the namespace itself but i keep having exceptions and nothing works.
I hope you can help me with this one.
Ty
You can use Instantiate https://docs.unity3d.com/ScriptReference/Object.Instantiate.html
to create an object as soon as Vuforia has recognizes a specific target (Wich you can check by using one of the targetablemanagers.)

Categories