How to activate a script from another object? - unity3d

I'm trying to activate a script from another object on a button press. Heres what I tried:
function Update () {
if(Input.touchCount == 1) {
GameObject.Find("theobject").GetComponent(thescript).enabled = true
}
else {
GameObject.Find("theobject").GetComponent(thescript).enabled = false
}
}
When I press play, It has no errors but when I press the button, nothing happens. Are there anything wrong with the script. I'm new to Unity and Javascript. Any help would be appreciated. Thanks in advanced!

This is what you can do:
if(GUI.Button(new Rect(10,10,100,90),"Button to activate object"))
{
gameObject.active = true;
}

Related

Jodit -> Hide Toolbar after initialization

i use Jodit as wysiwyg editor and have a beginner question.
At initialization of the editor, i want to hide the toolbar.
This works perfect:
var editor = new Jodit('#freitext_oben', {
fullsize: false,
toolbar: false,
editorCssClass: 'editor_freitext'
});
Now i want a custom button which calls a function that toggles the toolbar but i don't know how to set this option.
i need something like
function toggle_toolbar() {
editor.toggleToolbar();
}
But i don't know the exact syntax...
Please help ;-(
So here's a way that I've found to do this:
public ToggleToolbarVisibility()
{
if(!editor.editor.toolbar.container.style.display != "none")
{
editor.toolbar.container.style.display = "none";
}
else
{
editor.toolbar.container.style.display = "";
}
}

Fire rule when Enter Key is pressed. Adobe DTM

I have this code in my Custom code section of an event based rule in DTM. I am trying to fire the rule upon the Enter key press. The input is not within a form element. How to I get the Keycode scoped into my custom page code? Any help would be appreciated!
jQuery(this).keypress(function (e) {
if (e.keyCode == 13) {
var frmData = 'search:new:submit';
var inpData = jQuery(this).siblings('input').val().trim().toLowerCase();
_satellite.setVar('frmData', frmData);
_satellite.setVar('inpData', inpData);
return true;
}
});
I got it to fire by switching the event type to Keypress and using this simple code. -cheers
if (event.keyCode == 13){
return true;
}

Gui.Window won't show in Unity

I have some code like follwing:
if( GUI.Button(
new Rect(Screen.width/4f,50f,Screen.width/2f,Screen.height/9f),"RessetLevel")) {
showingWinsows = true;
if(showingWinsows)
{
rectWindow = GUI.Window(
0,
rectWindow,
DoMyWindow,
"Are you sure you want to reset All level ?"
);
}
I've insert the userGuiLayout = false; in my Awake() function. But the window still doesn't show. How do I fix this?
The problem is that the window is only drawn when the button is pressed.
You need to move the code that checks the flag out of the if( GUI.Button ), something like this:
if( GUI.Button(new Rect(Screen.width/4f,50f,Screen.width/2f,Screen.height/9f),"Resset Level"))
{
showingWinsows = true;
}
if(showingWinsows)
{
rectWindow = GUI.Window(0,rectWindow,DoMyWindow,"Are you sure you want to reset All level ?");
}

TinyMCE4 How to toggle selfcreated Buttons

I have created a Button with the Tiny Method addButton().
How is it possible to toggle the State of the Button ?
In my first simple case I have a Button with Fullscreen
(Different Functionality than the built-in function)
and want to hide it after getting the Fullscreen State
and replace it with an "End Fullscreen" Button.
But I have not found the right way to show or hide them.
I know that the button will get an ID, but I dont know which one ...
If you add the button with:
editor.addButton('customFullscreen', {
tooltip: 'Fullscreen',
shortcut: 'Ctrl+Alt+F',
onClick: toggleCustomFullscreen,
onPostRender: function() {
var self = this;
editor.on('CustomFullscreenStateChanged', function(e) {
if (e.state) {
self.name('Close fullscreen');
//self.active(e.state); // uncomment for "pressed" look
} else {
self.name('Fullscreen');
}
});
}
});
and handle the event with
var customFullscreenState = false;
function toggleFullscreen() {
customFullscreenState = !customFullscreenState;
if (customFullscreenState) {
// do something, we are active
} else {
// do something else, we're unactive
}
editor.fire('CustomFullscreenStateChanged', {state: fullscreenState});
}
You should be able to have it look like wo different button and do two different things depending on state, but it will still just be one button that changes action and text.

alert handling in ui automation iphone app unable to cancel the option

system.logElementTree();
var target = UIATarget.localTarget();
target.onAlert = function onAlert(alert) {
UIALogger.logDebug("There was an alert!");
target.onAlert.buttons()["No"].tap({x:164,y:278});
return false;
even though no option is clicked systen not performing any action
Can anyone please help me ...
Instead of BamboOS suggestion which loops through various positions, you can try this inside your onAlert function:
alert.tapWithOptions({tapOffset:{x:0.5, y:0.6}});
This tap targets the middle of the UIAAlert (x:0.5) and 60% from top to bottom (y:0.6). This works when there is only one button. You have multiple buttons, then you have to changed the value of x. This works for me.
I just published a blog post regarding UI Automation and dealing with alerts:
http://www.conduce.net/Blog.aspx?f=Automated-Test-of-iPad-Apps
Basically following alert handler worked for me:
UIATarget.onAlert = function onAlert(alert){
var name = alert.name();
UIALogger.logMessage("alert "+name+" encountered");
if(name == "errorAlert"){
var positionX = 500;
for(var positionY=300; positionY<600;positionY+=10){
target.tap({x:positionX,y:positionY});
}
return true;
}
return false;
}
I would either use the "cancelButton" or "defaultButton" methods when handling alerts.