Placing GameObjects in NPC: Difference between revisions

From Graal Bible
No edit summary
No edit summary
Line 1: Line 1:
Another way to make GameObjects visible to all the Players is by placing it in an NPC.  
Another way to make GameObjects visible to all the Players is by placing them in NPCs.  


However, placing many NPCs may be heavy on the server, so beware of that whenever you're doing so.
However, placing many NPCs may be heavy on the server, so beware of that whenever you're doing so.
Line 25: Line 25:
     this.projectile.transform.parent = this.gameobject.transform;
     this.projectile.transform.parent = this.gameobject.transform;
      
      
     this.projectile.transform.position = Vector3::Create(player.x, player.z + 2, player.y);
     this.projectile.transform.position = Vector3::Create(player.x, player.z + 2, player.y);  
    this.rigidBody = this.projectile.GetComponent(Type::RigidBody);
    this.rigidBody.AddForce(Vector3::Create(0,100,1500));
  }
  }
Everything is the same when it comes to loading and instantiating the prefabs.
The only difference is for this line of code:
{| class="wikitable"
!this.projectile.transform.parent = this.gameobject.transform;
|}
Here, '''''this.gameobject''''' is the NPC GameObject.
We make the prefabs instantiated children of the NPC GameObject. Destroying the NPC will destroy all the children as well. However, destroying the Children will not destroy the Parent.
Now to place the NPC in the scene, in another script and in serverside you use '''''putnpc2()''''' and joining it with the created class:
temp.pnpc = putnpc2(x, y, "");
temp.pnpc.join("merlin_bomberman_bomb");

Revision as of 04:10, 15 June 2021

Another way to make GameObjects visible to all the Players is by placing them in NPCs.

However, placing many NPCs may be heavy on the server, so beware of that whenever you're doing so.

Start off by creating the NPC the normal way:

Create a Script file in classes. You load the assets the same it was done before in weapons; under //#CLIENTSIDE

Placing GO in NPCs.png

function onPlayerChats() {
  if (player.chat == "/destroy") this.destroy();
}

function onCreated() {
  sleep(5);
  this.destroy();
}

//#CLIENTSIDE

function onCreated() {
    this.projectile = GameObject::createfromassetbundle("minigame", "assets/jimmyminigame/projectile.prefab");
    this.projectile = Object::Instantiate(Type::GameObject, this.projectile);
    
    this.projectile.transform.parent = this.gameobject.transform;
    
    this.projectile.transform.position = Vector3::Create(player.x, player.z + 2, player.y); 
}

Everything is the same when it comes to loading and instantiating the prefabs.

The only difference is for this line of code:

this.projectile.transform.parent = this.gameobject.transform;

Here, this.gameobject is the NPC GameObject.

We make the prefabs instantiated children of the NPC GameObject. Destroying the NPC will destroy all the children as well. However, destroying the Children will not destroy the Parent.

Now to place the NPC in the scene, in another script and in serverside you use putnpc2() and joining it with the created class:

temp.pnpc = putnpc2(x, y, "");
temp.pnpc.join("merlin_bomberman_bomb");