How do I detect Input.GetMouseButtonUp outside a specific GameObject's area in Unity? Are there any Unity Assets for this, or should we do this programmatically?
It certainly has to be done by programming it, whether there is an asset or not. As it is rather easy to program, I doubt there is one.
What you need to understand is, that Input.GetMouseButtonUp(int button) is an event and entirely decoupled from any "position". The description from the API says "Returns true during the frame the user releases the given mouse button.".
So in the frame a mouse button has been released you want to check if the arrow is "touching" or laying over some GameObject (GO). According to your example you will do nothing when the GO was hit, and else do something.
One way to do that is to use the following method:
http://docs.unity3d.com/ScriptReference/Camera.ScreenPointToRay.html
Your GameObject will at least need a collider, maybe a rigidbody too in order to be detected by the ray. I'm not completely sure atm if both are needed.
Additional note: Having an UI element, this method could also be used to set some flag while hovering over it e.g. : http://docs.unity3d.com/ScriptReference/MonoBehaviour.OnMouseOver.html
Related
How do I acess a script (or in my case rigidbody/collider) in a complex child-hierarchy, when the script is placed on mutliple gameobjects?
I want to call a function to set all the respective colliders to off with one click. The problem is, the colliders are placed on different gameobject within the RightHandController. The idea was to target the RightHandController, iterate down somehow and check if a colliders is attached and if so, disable it (see picture). Is there any good way to do this?
I have imported some Maximo animations, but when i use them i see that the character moves with the animation. when i walk for example i want it to be done via code and not the animation. how can i do this?
my animation rig is set to Humanoid, and also to loop when it ends.
i have tried to check if i can find it in the animation window, and if i can see the changes but no result. i think its the animation itself that changes its position. so please help me find this out or help me find another software where i can create an animation without moving the player.
i am talking about walking/running animations i need a way to not move it via the animation but via my character controller script.
Pretty sure you just need to turn off root motion.
https://docs.unity3d.com/ScriptReference/Animator-applyRootMotion.html
Just pick your avatar and uncheck "Apply root motion", or you can change it via code if you prefer.
Hi guys i was wondering how to create a shape adjustment with two objects which specifically could be described as the independent cells, one of which is static, and the second one is dynamic and surrounded by "plasma". The movement of the active object must be controllable by the user (WSAD). Collision of the active object with the static one causes the static object to be swallen, though doesn't change it's position stays in place all the time. As the active object moves, passes the swallen object and troughts it out.
See the image below:
Player character
When it comes close enough to pink enemy it's starting to swallow it (surround by yellow thing)
Pink enemy is completely sourrounded when red circle is in the centre of both.
When it leaves enemy it takes off the yellow thing
I was wondering what is the simplest way to do it. I've been thinking about cloth, physics joints, mesh substraction (is it even possible?), some kind of animation... I don't have much time to do it. Can you show me the simplest way. Which tools and approach should i use? I'm not asking for full code or full solution only for some tips.
Tim Hunter mentioned a wonderful way, most perfect in 3D.
You can use another approach in 2D :
Inside OnCollisionEnter2D try finding hit points using Collision2D.contacts . See this reference .
Create some particle effect there.
Disable the enemy
Now play swallowing animation of the player.
At animation end, enable enemy again.
Maybe calculation is little tricky, still efficient.
I'm coding a script in Unity that is applying a sequence of motions to my camera, for it to follow a predefined path. I need to repaint the scene in between every small motion otherwise the scene is drawn only when it reaches its final position.
I tried a lot of options but I just can't find something working for me.
I already tried :
SceneView.RepaintAll();
HandleUtility.Repaint();
and it can't find the Repaint() method from the Editor or EditorWindow classes.
Any idea ?
rendering process start after each Update(). Let process your motion logic in several Update with interpolation between each update.
With a whole bunch of copy-pasting from all over the web, I managed to hack together a piece of C# code which spawns a random object from an array when the player enters a large, spherical collision trigger. When the player leaves the trigger, the object is deleted. It's working almost as intended, only problem is that six out of ten times when the player passes through the collider, for a split second it feels like a physical collider. Meaning that although the player is trying to move straight forward, he or she will move left or right along the trigger collider for about half a second, before the object spawns and the player can move freely again.
I was under the impression that checking the "Is Trigger" box would remove all physical properties of that specific collider? Am I missing something?
I'm using the standard FPS Character Controller in Unity 5 if that might have something to do with it.
All help is greatly appreciated.
Make sure the spherical collision trigger has a rigid body component, and that the "Is Kinematic" property of the rigid body is checked.
Realized my solution didn't get posted as I thought it had. Yoyo's solution was correct. The object containing the code was also the trigger. Switched so that the player was the trigger and now all is well.