Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 1 year ago.
Improve this question
I want to be able to reference other functions inside my script, and then call them. Something like when assigning an on-click event for the button, so I can just drag and drop it in the Inspector. Thanks
You seem to mean a UnityEvent
public UnityEvent someName;
and later on at some point
someName.Invoke();
Otherwise just go via your type like e.g.
public YourOtherScript example;
and then
example.YourMethod();
you might mean calling a method/function from another class?
Then you could try referencing to that class by doing :
private yourclassName yourClassReferenceName;
Public void methodname()
{
yourClassReferenceName.ThefunctionFromTheOtherClass;
}
After you can drag and drop this class on the button and call the methodname(your method).
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 4 days ago.
Improve this question
Want to access ScriptableObject data from an editor code, namely a custom Node Graph Editor code:
Create a ScriptableObject containing Color field.
Create an instance of that SO and set the Color in the inspector.
Acquire that SO instance from an editor script.(if this was a Monobehavior we could drag drop into a SerializeField, how to achieve this from an editor script?)
Use the color from SO instance.
You can use :
SO SOInstance = Resources.Load("PATH_OF_YOUR_SO");
https://docs.unity3d.com/ScriptReference/Resources.Load.html
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
I'm new to swift language and xcode, and I've been stuck on this problem for weeks.
How can I get user input (from a textField) and turn it into a variable that I can use in my code?
Thank you.
All you need to do is:
let userInput = textField.text
Make sure you place the code inside of the function that is called when the user is finished editing.
For example, if you have a confirm button, you would probably want to initialize this variable inside of the function that is called when the user taps the confirm button.
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 3 years ago.
Improve this question
I am calling a function in a different class that simply removes a lottie animation. I do this by calling...
RedeemController().removeAnimationFromSuperview()
Which enters the function (as proven by a print statement). However the animation does not disappear from the view.
When I call the same function from within the class that the animation is defined, the animation is removed from the view as expected. Here is the function. Very simple.
fileprivate func removeAnimationFromSuperview(){
animationViewDraw.removeFromSuperview()
print("Entered")
}
I would expect this animation to disappear. Thanks for your help!!!!
You are creating new instance of RedeemController that has it's own properties, instead you have to use the instance that you currently have
myControllerInstance.removeAnimationFromSuperview()
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
In my Login screen, after the login has been accepted, a number is given to that particular user as UserNum so i can access information stored in arrays.
My question is: how can i use this variable across all of my viewControllers to display the information that i get from using my array?
One way to do this is creating a new Swift Files, and make a struct with static variables like this:
struct CommonValues {
static var UserNum: Int = 0
}
And then, you modify it in any view controller if you need it.
You maybe should save it and load it as well, I recommend UserDefaults for that.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I wrote a custom button which is basically a NSView subclass. The button reacts on mouseDown() and should run a selector/action.
I don't know how to add a target and action variable to the subclass (similar to user interface elements like NSButton). I tried
var target : AnyObject?
var action: Selector?
Also how do I run the selector with the target in my subclass?
The "target/action" pair is archaic and should be avoided. But if you really wanted to use it, have a look at the NSApplication sendAction(_:to:from:) method.
Or if your custom button extends NSControl, you can use its target and action properties and its sendAction(_:to:) method.
A more modern approach would be to provide a closure property for your button class and then call that closure instead of using a target/action pair. Using a closure is safer, cleaner, and probably makes client code of your button class easier to write.