Placing GameObjects in NPC: Difference between revisions

From Graal Bible
(Created page with "Another way to make GameObjects visible to all the Players is placing it in an NPC. However, placing many NPCs may be heavy on the server, so be aware of that whenever you're...")
 
No edit summary
Line 1: Line 1:
Another way to make GameObjects visible to all the Players is placing it in an NPC. However, placing many NPCs may be heavy on the server, so be aware of that whenever you're placing GameObjects in NPCs.
Another way to make GameObjects visible to all the Players is by placing it in an NPC.  


Start off by creating the NPC the normal way; by creating a new class. Inside that class you load the AssetBundle in ClientSide
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'''
 
[[File:Placing GO in NPCs.png|frameless|1049x1049px]]
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);
    this.rigidBody = this.projectile.GetComponent(Type::RigidBody);
    this.rigidBody.AddForce(Vector3::Create(0,100,1500));
}

Revision as of 10:46, 14 June 2021

Another way to make GameObjects visible to all the Players is by placing it in an NPC.

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);

    this.rigidBody = this.projectile.GetComponent(Type::RigidBody);
    this.rigidBody.AddForce(Vector3::Create(0,100,1500));
}