Need help with onclick model creation script


#1

Hey,

I was wondering if there is an easy way to combine the createCow tutorial script with some kind of onClick event or even some kind of “entering a zone” event.

I am wanting it where a model will spawn when a user clicks onto another model (let’s say a cube). Can I get some assistance with this?

Thanks


#2

Theres a couple of issues stopping a simple answer to your request but I will do my best.

The createCow script is a client script but a click entity is an entity script so there needs to be some extra code changes to make the 2 work together, heres a simple click entity script to change colors.

(function(){
var clicked = false;
this.mousePressOnEntity = function(entityID, mouseEvent) {
if (clicked){
Entities.editEntity(entityID, { color: { red: 0, green: 255, blue: 255} });
clicked = false;
}else{
Entities.editEntity(entityID, { color: { red: 255, green: 255, blue: 0} });
clicked = true;
}
};
})

put that in a cube and click it, now play with the params and get to know it.
here is its bare bones, look at the log for the “Clicked” output to know its working.

(function(){
this.mousePressOnEntity = function(entityID, mouseEvent) {
print(“clicked”);
};
})

(edited to remove some incorrect info)
So start with a simple Entities.addEntity before you try to create that cow with its scripts and animations.


#3

If you prefer the enter instead of click then just replace

this.mousePressOnEntity = function(entityID, mouseEvent)

with

this.enterEntity = function(entityID)

and make it big enough and remove any collisions so you can actually enter it, and make it invisible for obvious reasons, but in my experience the enter entity tends to trigger more than once and this can cause issues.