I have a script which changes the scene view depending on what you click on. Bascially, some things I want to auto ‘Align view to selected’. But, not always. So I would like to use the ‘alt’ key as a modifier. Detect that the selection has changed, and check if the alt key is currently down. Not having much luck with this.
2 Answers
2Answer this old question because I’ve been doing a lot of the same and finding few answers:
Check out Event.current.modifiers to check for different modifying keys (shift, ctrl, alt, etc).
Example - On a left click, check if shift was held down:
if (Event.current.type == EventType.MouseDown && Event.current.button == 0){ //if both control and alt keys pressed if (Event.current.modifiers == (EventModifiers.Control | EventModifiers.Alt)) Debug.Log("AH HA!"); }
Check out the Event.control, Event.alt and Event.shift booleans.
You can get the current event status with Event.current, and check that variable for the boolean values mentioned above.
Well, it's not ^^. Fattie himself did edit the accepted answer to insert his answer into the accepted one since the original author of the accepted answer hasn't been seen since 2019. When you check the revision history, you will notice that the last changes of the accepted answer were done by Fattie. (Note the revision history is a bit messy, but should record any changes made).
– Bunny83