Questions in topic: "event"http://answers.unity3d.com/questions/topics/single/306.html
The latest questions for the topic "event"Using the Viewfield of the Vive as a triggerhttp://answers.unity3d.com/questions/1278516/using-the-viewfield-of-the-vive-as-a-trigger.html
Hi,
does anyone know how to use the viewfield of a HTC Vive as a trigger for an event in VR?
GreetztriggereventviewcontrollerWed, 30 Nov 2016 14:12:52 GMTHollasunIs it Bad Practice to Raise Event in Update?http://answers.unity3d.com/questions/1278281/is-it-bad-practice-to-raise-event-in-update.html
I'm trying to figure out if I'm raising an event too often. I have a Player class which calls a raycast during its Update(), and raises an event if the ray collides with anything:
Player()
{
void Update()
{
RaycastHit hit;
// Raise event if player detects anything.
if (Physics.Raycast(m_Transform.position, m_Transform.forward, out hit, m_MaxRayDistance))
{
OnPlayerDetect(hit.collider, hit.distance);
}
}
}
Part of me thinks that this is not the best use for events. I'm afraid that this might be inefficient and have potential to slow down the game if there are too many subscribers.
Is this a good use of the event? If not, what's an example of a more efficient way?eventpracticeWed, 30 Nov 2016 00:51:42 GMTDyn0myte_beko توكيل غسالات بيكو 01023140280 صيانة بيكو فرع الجيزة 0235700994http://answers.unity3d.com/questions/1276964/beko-%D8%AA%D9%88%D9%83%D9%8A%D9%84-%D8%BA%D8%B3%D8%A7%D9%84%D8%A7%D8%AA-%D8%A8%D9%8A%D9%83%D9%88-01023140280-%D8%B5%D9%8A%D8%A7%D9%86%D8%A9-%D8%A8%D9%8A%D9%83%D9%88-%D9%81%D8%B1%D8%B9.html
beko توكيل غسالات بيكو 01023140280 صيانة بيكو فرع الجيزة 0235700994 beko توكيل غسالات بيكو 01023140280 صيانة بيكو فرع الجيزة 0235700994 beko توكيل غسالات بيكو 01023140280 صيانة بيكو فرع الجيزة 0235700994 beko توكيل غسالات بيكو 01023140280 صيانة بيكو فرع الجيزة 0235700994 beko توكيل غساeventSun, 27 Nov 2016 12:17:07 GMThoommmButton.onClick how to pass parameter?http://answers.unity3d.com/questions/1276501/buttononclick-how-to-pass-parameter.html
A button in class UIManager, when the button click, how to pass params(such as scene name) to the method LoadLevelByName in class LevelManager .
public class UIManager : MonoBehaviour {
[SerializeField]
private Button _startButton;
void Start ()
{
_startButton.onClick.AddListener(LevelManager.Instance.GotoLevel);
}
}
public class LevelManager : MonoBehaviour
{
public static LevelManager Instance;
public UnityAction GotoLevel;
void Awake ()
{
if ( Instance == null )
{
Instance = this;
DontDestroyOnLoad(this.gameObject);
}
else if ( Instance != null )
{
Destroy(this.gameObject);
}
}
void Start ()
{
GotoLevel = () => LoadLevelByName();
}
public void LoadLevelByName (string levelName)
{
SceneManager.LoadScene(levelName);
}
}eventdelegateSat, 26 Nov 2016 04:21:42 GMTMinarstilisMecanim - How to figure out the State and layerIndex that triggered Animation Clip Event?http://answers.unity3d.com/questions/1275535/mecanim-how-to-figure-out-the-state-and-layerindex.html
When I trigger an Event in Mecanim using the 'Animation Clip Events', how can I know what is the state and layerIndex that contains the Animation Clip that triggered that event?mecanimeventlayerstateclipWed, 23 Nov 2016 21:34:59 GMTcastorcall PointerUp event of a button from other game object's script.http://answers.unity3d.com/questions/1275453/call-pointerup-event-of-a-button-from-other-game-o.html
Question says it all . I want to call pointerUP event of a button from other script. Is there any way to do it.buttoneventWed, 23 Nov 2016 18:45:19 GMTMadKiddocreaterGUI.Window makes custom EditorWindow drag header unresponsivehttp://answers.unity3d.com/questions/1274538/guiwindow-makes-custom-editorwindow-drag-header-un.html
I've made a custom EditorWindow that displays a lot of "GUI.Window"s and I've made them all draggable using the "GUI.DragWindow" method. Moving a draggable gui window around makes the overall EditorWindow header (the top horizontal strip of the window you can click on to drag the window around) unresponsive.
I believe this has something to do with how "GUI.DragWindow" processes the current event. I manually process all of the events that happen in the EditorWindow and use the current event through "currentEvent.Use()". I don't manually "Use" the current event when the user clicks on a "GUI.Window", because doing so would stop the "GUI.DragWindow()" from working (the windows are no longer draggable). However, using the event before GUI.DragWindow does stop the overall EditorWindow from becoming unresponsive.
Has anyone else come across this issue? And if so, could you advise as to how I might approach solving this (have both the GUI.DragWindow windows and the overall EditorWindow be responsive)
Thanks in advance.
MattguieventeditorwindowdragwindowMon, 21 Nov 2016 21:09:28 GMTmatski53Deactivating object makes events null. What is the best workaround?http://answers.unity3d.com/questions/1274492/deactivating-object-makes-events-null-what-is-the.html
public delegate void HandworkAction();
public event HandworkAction grab;
After deactivating the object that contains the script, and reactivating it again, events become null, causing nullreference exception. Is this by any change a bug, why does this happen and what do you recommend me to do?gameobjecteventeventsMon, 21 Nov 2016 19:24:47 GMTAvashIn Canvas, how do I require several triggers for a single event?http://answers.unity3d.com/questions/1274037/in-canvas-how-do-i-require-several-triggers-for-a.html
I am quite new to Unity and I feel that attempting to post any code might be a waste of our time. Basically, I am using Canvas to make a menu, and within that menu are several images that I want to have all be clicked on in order for a "secret menu item" to appear. I think I could get this working for a single item, but having multiple images to click has me lost. I have set up an Event Trigger with the EventTrigger.enabled function but I don't know how to translate that through code and with multiple clicks needing to be triggered in order for the secret button to appear. Any code or tips would be greatly appreciated. Thanks in advance.uieventtriggersSun, 20 Nov 2016 20:33:36 GMTdaant123Unity Duplicate Eventhttp://answers.unity3d.com/questions/1274030/unity-duplicate-event.html
Hi Everyone,
I could use some help getting the Duplicate event in editor.
I've tried catching 'Paste' and 'Duplicate' but they do not get called when I look for them.
Additionally, I've tried to put an event handler in the `EditorApplication.hierarchyWindowItemOnGUI` to see if the commands are caught inside that but those commands do not appear.
Catching duplicate events in Unity is one of the single most frustrating things I've dealt with in Unity. It feels like handling this was an afterthought...
Any help is appreciated.editor-scriptingeventduplicateSun, 20 Nov 2016 20:22:26 GMTLWAdd Event Button not showing uphttp://answers.unity3d.com/questions/1271421/add-event-button-not-showing-up.html
I'm trying to add footsteps to my character. I've followed this tutorial: https://www.youtube.com/watch?v=7GnKZUvfQIo however I don't have the add event button in the Animation tab. Even when I managed to bring it up it was greyed out and I couldn't click on it. After I restarted Unity, the button disappeared again.
![alt text][1]
How do I get to the Add Event button? Or is there any other way I can use a function to add footprints?
Thanks
[1]: /storage/temp/82190-untitled.pngeventanimation editorMon, 14 Nov 2016 19:58:27 GMTRinisraOnClick SphereCap Handleshttp://answers.unity3d.com/questions/1271403/onclick-handles-spherecap.html
I write editor extension for drawing vectors (using Handles class).
I use Handles.FreeMoveHandle with two SphereCap at the edges of vector for moving and scaling.
How i can detect onClick event on SphereCap?
I found this code, but it not working:
var newId = GUIUtility.GetControlID(vectorObj.Hash, FocusType.Passive);
switch (e.GetTypeForControl(newId))
{
case EventType.Layout:
HandleUtility.AddControl(newId, 0.05f);
HandleUtility.AddDefaultControl(newId);
break;
case EventType.MouseUp:
Debug.Log("id: " + newId + " nearest: " + HandleUtility.nearestControl); // newId != HandleUtility.nearestControl i don't know how to fix it
break;
}
for now, i can detect vector selection only if one of SphereCap was moved, but i want catch it onClick. any ideas?
![alt text][1]
[1]: /storage/temp/82185-0131380d85.jpgshaderseventhandlesMon, 14 Nov 2016 19:29:08 GMTmoney4honeyHow to access the OnClick event via Scripthttp://answers.unity3d.com/questions/1271229/how-to-access-the-onclick-event-via-script.html
I am trying to do a SongManager object which will be responsible for changing songs. I created a SongManager and a Song script. On runtime SongManager creates as many song buttons as i want each with different variables. Everything seems to work fine except that i cant get to OnClick event to change the songs.I tried many things but i guess its all outdated. Stuff like:
public Button.ButtonClickedEvent OnClickEvent;
or
go.GetComponent<Button>().onClick.AddListener();
Appreciate any help, thank u guys.
![alt text][1]
![alt text][2]
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
using System.Collections.Generic;
using UnityEngine.EventSystems;
public class SongManager : MonoBehaviour {
[System.Serializable]
public class Song
{
public string SongName;
public int Unlocked;
public bool isInteractable;
public AudioClip clip;
}
public GameObject button;
public Transform panel;
public List<Song> songList;
void Start ()
{
FillList();
}
void FillList()
{
foreach (var song in songList)
{
GameObject newButton = Instantiate(button) as GameObject;
SongButton songButton = newButton.GetComponent<SongButton>();
songButton.songName.text = song.SongName;
songButton.clip = song.clip;
newButton.transform.SetParent(panel, false);
}
}
}
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class SongButton : MonoBehaviour
{
public Text songName;
public int unlocked;
public AudioClip clip;
}
[1]: /storage/temp/82153-sample1.png
[2]: /storage/temp/82155-preview2.pnguibuttonaudioeventonclickMon, 14 Nov 2016 11:40:21 GMTRicharrd82Is there anyway to stop event propagationhttp://answers.unity3d.com/questions/1262263/is-there-anyway-to-stop-event-propagation.html
Hi,
I have a pause button while playing game, so my player has behavior to move wherever touched. So when pause button clicked , player moves towards pause button.
Tried OnPointerClicked Interface on pause button but not working.
Current workaround is when player moves i set pause (image) raycast to false and using if(EventSystem.current.IsPointerOverGameObject()) return in Fixed Update Input.touchCount of Player
But it is making things clunky as player has to move continuously.
Is there any method like event.stopPropagation() or some thing similar? Thanks in Advance!gameobjectuieventTue, 25 Oct 2016 17:11:46 GMTmeuklightQuestSystem: the right wayhttp://answers.unity3d.com/questions/1259446/questsystem-in-the-right-way.html
### The problem ###
Hi guys, I read a lot about QuestSystem but everytime I found only bad monobehaviour-based patterns that I really don't like ("use triggers...!", "use colliders...!", ecc... I hate this kind of programming). [My english is not good ;)]
So, I decided to write a QuestSystem based to interfaces and events, but are 2 days that I'm stuck with the event system.
----------
### The objects ###
I will try to summarize, I have:
1. **IQuestObjective**: an interface with *UpdateProgress()* method and *OnComplete* event; it's a simple task for complete a quest.
2. **Quest**: an object with a List of **IQuestObjective**. In this way, for example, a single Quest can have multiple tasks. For each objectives the quest adds itself to the *OnComplete* event. So, when all of the objectives are completed, the quest will too.
3. Various type of **IQuestObjective** like *CollectionObjective* (collect *this*, *this* and *that*), *InteractionObjective* (talk with *P*), *LocationObjective* (go to *K* position), etc...
4. A lot of other stuff.
The problem is that I'm stuck with the event system network between the QuestManager, the Player, the locations, the npcs, ecc...
----------
### Questions ###
I will take the example of the *InteractionObjective* (talk with *X*). Every NPC monobehaviour has a *Character* model assigned to, with some cool informations and stuff like the dialogues he has to show when the player interact with, or the quests he has to show. All of these interactions are done inside an **Interact()** method.
What should be the right flow and what are the events I must to implement?
Should be the *QuestManager* to managed all the event flow? How?
It's the first time I'm approaching to a "complex" event system and I have a lot to learn. Unfortunately I think the best way is always "try and try and try...".
If you need **I can post my code**, but is a lot of code and a lot of classes (OOP)c#eventrpgquestThu, 20 Oct 2016 09:55:05 GMTxxZapis it possible to save over animation clips and keep events?http://answers.unity3d.com/questions/1258535/is-it-possible-to-save-over-animation-clips-and-ke.html
In the nature of the animation industry, animations go through a lot of revisions. And when I export a new animation take from Maya, I save over the existing animation take, but when I do that, event data has been lost. Is there a way to make revisions, without having to re-set up the events or re-attach clips?animationeventanimationclipanimationeventTue, 18 Oct 2016 22:18:56 GMTOrchamedesMaterial transition through animationhttp://answers.unity3d.com/questions/1258254/material-transition-through-animation.html
I have this script that ping pongs back and forth between two materials (doesn't transition textures but that's fine with me for what I'm doing). How would I change it so that instead of ping ponging I can cause the transition to happen through using animation events? So, I could have an animation that on frame 60 I trigger a transition to material 2 and on frame 120 transition back to material 3.
using UnityEngine;
using System.Collections;
public class swap_mats : MonoBehaviour {
// Blends between two materials
public Material material1;
public Material material2;
public float duration = 2.0F;
public Renderer rend;
void Start() {
// At start, use the first material
rend = GetComponent<Renderer>();
rend.material = material1;
}
void Update() {
// Ping-pong between the materials over the duration
float lerp = Mathf.PingPong(Time.time, duration) / duration;
rend.material.Lerp(material1, material2, lerp);
}
}animationmateriallerpeventswapTue, 18 Oct 2016 12:23:39 GMTtylerlybbActivate 2 separate OnClick events, with the different Mouse Buttonshttp://answers.unity3d.com/questions/1253076/activate-2-separate-onclick-events-with-the-differ.html
I know i can make a OnClick with the left Mouse Button, but is it possible to make another OnClick in the same Button, with right Mouse Button ?buttonmouseeventonclickright clickFri, 07 Oct 2016 10:59:31 GMTLev_KingDetecting moment when GameObiect is created in hierarchy.http://answers.unity3d.com/questions/1243289/detecting-moment-when-gameobiect-is-created-in-hie.html
Hi,
I need to know moment when any new GameObject is added to hierarchy (from project window, CtrlD, code etc). I know about EditorApplication.hierarchyWindowChanged but it gives me no informatian what type of change it was. In general i want sth like "SuperHelpfulEditorClass.onGameObiectCreated". Any ideas?c#gameobjecteditoreventhierarchyWed, 14 Sep 2016 12:27:02 GMTxenix2012Notify a script that a transform has changed its parenthttp://answers.unity3d.com/questions/1239660/notify-a-script-that-a-transform-has-changed-its-p.html
So I have a script that, when i put in on an object, it changes the materials of all the children of that object (inlcuding children of children).
I may have this structure:
**root object with the script**
--- level 1 child
--- level 1 child
------ level 2 child
------ level 2 child
--------- level 3 child
All the materials of these direct children and deep children will be changed.
The thing is that I want an event to know when let's say a child from level 2 or level 3 is removed from this mini-hierarchy, so that I change the materials back to what they were before.
I know that **OnTransformParentChanged**() is called when a gameobject's parent changed, but I cannot use this function, as I do not want to attach a script to all these children. I want to have only the script on my root object.
There is also **OnTransformChildrenChanged**() that I can overwrite in the script of the root object, but this gets called only when a level 1 child changed its parent.
How would you guys do this? I would like some sort of an event that works like **OnTransformChildrenChanged**() that also works with deep children, but please tell me if you have another solution. (PS, I would like to not use **Update** to constantly check)transformscripting problemparenteventchildrenMon, 05 Sep 2016 19:22:22 GMTsilviu-georgian77Toggle's 'On Value Changed' checkbox is shown for bool parameter functionhttp://answers.unity3d.com/questions/1239099/toggle-on-value-changed-checkbox-is-shown-for-bool.html
I wonder is it a bug or not, because I don't remember such behaviour before.
If I set `SetActive` function, there is no checkbox, if then I change function to custom, checkbox appears. Example of signature:
`public void ToggleColorNames(bool show)`
If then I switch back to `SetActive` function, checkbox is still there. So at least the last part is a bug. I workarounded that, but I just want to know.uieventtoggleSun, 04 Sep 2016 09:19:23 GMTNecronomicronCan´t find the infinite loop in this scripthttp://answers.unity3d.com/questions/1236231/cant-find-the-infinite-loop-in-this-script.html
Hi, I´m making a game where my character should be able to hit, and only change to idle state (or any other anim state) if the "hit animation" ends. To achieve that I used an event function and a boolean .
The thing is that, if I tap rapdly the "S" key (really fast, probably matching the exact frame where the animation event function gets called), the player freezes at the last frame of the hit animation, not the game, but the player.
I guess it is an infinite loop since the console doesn´t notify anything.
Any ideas??
using UnityEngine;
using System.Collections;
public class leono : MonoBehaviour {
public float moveSpeed;
private Animator animator;
private bool fighting;
void Awake () {
animator = GetComponent<Animator>();
}
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
//Player hit
if (Input.GetKeyDown (KeyCode.S)&& !fighting) {
Debug.Log (" fighting true ");
fighting = true;
animator.SetInteger ("leono", 2);
}
//Player move right
else if (Input.GetKey (KeyCode.RightArrow) && !fighting ) {
transform.localScale = new Vector3 (1f, 1f, 1f);
animator.SetInteger ("leono", 1);
GetComponent<Rigidbody2D> ().velocity = new Vector2 (moveSpeed, GetComponent<Rigidbody2D> ().velocity.y);
}
//Return to idle from moving right
if (Input.GetKeyUp (KeyCode.RightArrow)&& !fighting ) {
animator.SetInteger ("leono", 0);
}
//Player move left
else if (Input.GetKey (KeyCode.LeftArrow)&& !fighting ) {
transform.localScale = new Vector3 (-1f, 1f, 1f);
animator.SetInteger ("leono", 1);
GetComponent<Rigidbody2D> ().velocity = new Vector2 (-moveSpeed, GetComponent<Rigidbody2D> ().velocity.y);
}
//Return to idle from moving left
if (Input.GetKeyUp (KeyCode.LeftArrow)&& !fighting ) {
animator.SetInteger ("leono", 0);
}
}
//This function gets called at the end of the animation with an animation event
void defaultState (){
fighting = false;
Debug.Log (" fighting false ");
animator.SetInteger ("leono", 0);
}
}animationloopbooleaneventinfiniteMon, 29 Aug 2016 10:23:10 GMTpatosalasIPointerEnterHandler calls immediately after IPointerExitHandlerhttp://answers.unity3d.com/questions/1231154/ipointerenterhandler-calls-immediately-after-ipoin.html
Hello guys, I got a problem in my app. I have a images in my scene and for detecting an actions I implemented follow interfaces: IPointerDownHandler, IPointerUpHandler, IPointerEnterHandler, IPointerExitHandler
I looked at the log and noticed that when I press and then release the image on device by finger IPointerEnterHandler event calls immediately after IPointerExitHandler. This problem occurs just on the device however in the editor everything is working well.Some one know what could be the reason of this strange behavior?
ThankseventeventseventsystemThu, 18 Aug 2016 14:35:57 GMTlomaikabiniWhat Are The Proper Conversions For Key Input in 5.4?http://answers.unity3d.com/questions/1229799/what-are-the-proper-conversions-for-key-input-in-5.html
From what I currently know, they way to do an event on key press is to have an Update method in some kind of MonoBehaviour that checks for whatever Boolean and then it runs the corresponding doodads if the condition is met. I'm looking to save on performance where possible an reduce the number of reflection calls in my Unity game, so I don't want Update being called to check for a key press isn't going to be constantly pressed. I feel like having several entities on screen that all use Update can be a severe performance drop.
Is there some kind of event method I can use that only gets called when a key is pressed then I check for which key was pressed? I've seen example of this done in OnGUI, but isn't everything to do with GUI scripting being depreciated in favor of more Canvas based things? I don't really want to regress if that's the case.inputupdateeventreflectionkeypressMon, 15 Aug 2016 18:08:48 GMTghostravnestormInformation about when it is destroyed any GameObject on scene.http://answers.unity3d.com/questions/1229624/information-about-when-it-is-destroyed-any-gameobj.html
Hello,
I have a scene where I have a lot of GOs and an editor script that is used to work with this scene. In this script, I would like to know when is destroyed any of scene objects (by using delete in hierarchy, by code or anything else). Any ideas? (maybe destroying GO is rising global event and I can simply sign up to it?)gameobjecteditordestroyeditor-scriptingeventMon, 15 Aug 2016 09:05:40 GMTYerendiAddListener to OnPointerDown of Button instead of onClickhttp://answers.unity3d.com/questions/1226851/addlistener-to-onpointerdown-of-button-instead-of.html
I'd like to register a callback to the *OnPointerDown* and *OnPointerUp* events of the *UnityEngine.UI.Button*(s) in my game to trigger two different sounds for down and up click. However, only the *onClick* event is exposed. Is there any clean method to get these properties through code? I'd rather not add the *UnityEngine.EventTrigger* component to every button individually and set them up in the scene, because of the amount of buttons in my project and I might want to change behaviour while testing, and therefore rather do it from one central location in code.c#buttoneventMon, 08 Aug 2016 20:47:52 GMTXarbroughHow to bind OnClick event to Singleton function?http://answers.unity3d.com/questions/1224440/how-to-bind-onclick-event-to-singleton-function.html
I want to bind OnClick event of UI Button to a function in Singleton object. I tried to do that, but every time I go to other scene and get back to the old scene I find that object disappear from the onClick field in the inspector while it's exist in the hierarchy !
If it's not possible to do that, what's the alternative way ?
Note: I'm using c#eventsingletonTue, 02 Aug 2016 22:58:29 GMTdotWasimHow does GetTypeForControl work? Maybe bug?http://answers.unity3d.com/questions/1222065/how-does-gettypeforcontrol-work.html
I thought GetTypeForControl(id) returns type (not Ignore value) only if ```GUIUtility.hotControl == id```.
But I see that GetTypeForControl(id) also returns type for controls with lower id.
For example:
let GUIUtility.hotControl = 100;
GetTypeForControl will return type for id 90 and id 100. But not for 101.
You can see it on this video: https://youtu.be/h_wbp_gM60s
Code:
public static void Draw(Rect position, Texture texture, Material material, Transform trans) {
Graphics.DrawTexture( position, texture, material );
using(new GUI.ClipScope( position )) {
position.position = Vector2.zero;
Matrix4x4 coordSystem = TranslateScaleMatrix( new Vector2(position.x, position.height), new Vector2(position.width, -position.height) );
DoViewer( position, trans, coordSystem.inverse );
}
}
private static void DoViewer(Rect position, Transform trans, Matrix4x4 coordSystem) {
int id = GUIUtility.GetControlID( position.GetHashCode(), FocusType.Passive );
EventType type = Event.current.GetTypeForControl(id);
if(type.IsMouseDown(1)) {
GUIUtility.hotControl = id;
Event.current.Use();
}
if(type.IsMouseUp(1)) {
GUIUtility.hotControl = 0;
Event.current.Use();
}
if(type.IsMouseDrag(1)) {
Debug.Log( "hot: "+GUIUtility.hotControl+" id: "+id );
Vector2 delta = Event.current.delta;
delta = coordSystem.MultiplyVector(delta);
trans.position += (Vector3) delta;
GUI.changed = true;
Event.current.Use();
}
if(type.IsScrollWheel()) {
Vector2 mouse = Event.current.mousePosition;
mouse = coordSystem.MultiplyPoint(mouse);
Vector2 pos1 = trans.InverseTransformPoint( mouse );
if(Event.current.delta.y < 0) trans.localScale *= 1.15f;
if(Event.current.delta.y > 0) trans.localScale /= 1.15f;
Vector2 pos2 = trans.InverseTransformPoint( mouse );
var delta = trans.TransformVector(pos2 - pos1);
trans.position += (Vector3) delta;
GUI.changed = true;
Event.current.Use();
}
}
This is code of GetTypeForControl from Unity 3. In last version of Unity this code is moved to native.
public EventType GetTypeForControl(int controlID)
{
if (GUIUtility.hotControl == 0)
{
return this.type;
}
switch (this.m_Type)
{
case EventType.MouseDown:
case EventType.MouseUp:
case EventType.MouseMove:
case EventType.MouseDrag:
if (!GUI.enabled)
{
return EventType.Ignore;
}
if (GUIClip.enabled || GUIUtility.hotControl == controlID)
{
return this.m_Type;
}
return EventType.Ignore;
case EventType.KeyDown:
case EventType.KeyUp:
if (!GUI.enabled)
{
return EventType.Ignore;
}
if (GUIClip.enabled || GUIUtility.hotControl == controlID || GUIUtility.keyboardControl == controlID)
{
return this.m_Type;
}
return EventType.Ignore;
case EventType.ScrollWheel:
if (!GUI.enabled)
{
return EventType.Ignore;
}
if (GUIClip.enabled || GUIUtility.hotControl == controlID || GUIUtility.keyboardControl == controlID)
{
return this.m_Type;
}
return EventType.Ignore;
default:
return this.m_Type;
}
}guieventguiutilityhotcontrolThu, 28 Jul 2016 10:14:16 GMTDeni35StartCoroutine by another class (Coroutine inside Coroutine - Instance class)http://answers.unity3d.com/questions/1220217/startcoroutine-by-another-class-coroutine-inside-c.html
Hi, we have this class:
using UnityEngine;
using System.Collections;
using UnityEngine.SceneManagement;
public class ScreenManager : MonoBehaviour {
[SerializeField]
private EFXManager m_blackScreenCover;
[SerializeField]
private EFXManager m_form;
[SerializeField]
private float m_minDuration = 1.5f;
public static ScreenManager instance = null;
void Awake()
{
if (instance == null)
instance = this;
else if (instance != this)
Destroy(gameObject);
DontDestroyOnLoad(gameObject);
}
void Update()
{
//if (Input.GetMouseButtonDown(0))
//{
// StartCoroutine(LoadSceneAsyncScale("GameScreen"));
//}
}
public IEnumerator LoadSceneAsyncScale(string sceneName)
{
// Scale IN
yield return StartCoroutine(m_form.ScaleIn());
// Load loading screen
yield return SceneManager.LoadSceneAsync("LoadingScreen");
// !!! unload old screen (automatic)
// Fade to loading screen
yield return StartCoroutine(m_blackScreenCover.FadeOut());
float endTime = Time.time + m_minDuration;
yield return SceneManager.LoadSceneAsync(sceneName, LoadSceneMode.Additive);
while (Time.time < endTime)
yield return null;
// Fade to black
yield return StartCoroutine(m_blackScreenCover.FadeIn());
// !!! unload loading screen
LoadingSceneManager.UnloadLoadingScene();
// Scale to new screen
yield return StartCoroutine(m_form.ScaleOut());
}
}
We are calling the method `LoadSceneAsyncScale` through another class. Everything seems to go well, but the method in question have more Coroutines ( `yield return StartCoroutine (m_blackScreenCover.FadeOut ();` for example ) and we noticed that it does not run. The implementation of the method will only `LoadSceneAsyncScale` to call `yield return SceneManager.LoadSceneAsync ("LoadingScreen");` What could be going wrong? The call is incorrect?
My call:
using UnityEngine;
using System.Collections;
using UnityEngine.EventSystems;
using UnityEngine.UI;
public class EventManager : MonoBehaviour
{
public void OnButtonClick()
{
StartCoroutine(ScreenManager.instance.LoadSceneAsyncScale("GameScreen")); //<< THIS IS A CALL, DON'T WORKS!
}
}
But when we called directly from the class that has the method, in the Update () function could perform all routines:
public class ScreenManager : MonoBehaviour {
//........
void Update()
{
StartCoroutine(LoadSceneAsyncScale("GameScreen")); //<< THIS WORKS FINE!
}
//........
}
What are we doing wrong? Remembering that we are using the Singleton pattern.
Thanks a lot!
**[SOLUTION]**
With the help of the @Bunny83 response, we can implement the `Singleton pattern` in the class that will call the coroutine ( `EventManager` ) so the calling object will not be destroyed! Or just do what the @Bunny83 said in your answer!
using UnityEngine;
using System.Collections;
using UnityEngine.EventSystems;
using UnityEngine.UI;
public class EventManager : MonoBehaviour
{
public static EventManager instance = null;
void Awake()
{
if (instance == null)
instance = this;
else if (instance != this)
Destroy(gameObject);
DontDestroyOnLoad(gameObject);
}
public void OnButtonClick()
{
StartCoroutine(ScreenManager.instance.LoadSceneAsyncScale("GameScreen"));
}
}
Thanks @Bunny83 ;)coroutineclasseventcoroutinessingletonSun, 24 Jul 2016 08:41:48 GMTIgorUnity3DUsing OnClick() with an empty GameObjecthttp://answers.unity3d.com/questions/1219370/using-onclick-with-an-empty-gameobject.html
![][1]
I've used this interface before, but when I click the browse button next to the *None (Object)*, I can't seem to find the GameObject (called gameController) where I keep the script I want to reference. gameController is composed only of a transform and the script I'm trying to reference.
Why can't I (and how do I) reference that GameObject from here? I'm fairly new to Unity, so be suspicious of me not understanding how OnClick() works.
Cheers!
[1]: /storage/temp/74609-capture.pngeventclickevent triggeringreferencingempty game objectFri, 22 Jul 2016 08:49:52 GMTianbo