News: Enjoy our Christmas offer 30% off on our latest package Tower Defense Level Kit http://u3d.as/m7h

  • November 21, 2018, 05:46:38 AM

Login with username, password and session length

Author Topic: access game entity faction  (Read 1064 times)

Offline haim

  • Newbie
  • *
  • Posts: 8
access game entity faction
« on: July 04, 2016, 03:56:57 PM »
Hi,

as far as i understand factions control how entity will treat each other.
what if i need to change faction in run time? (i need a game object to ignored by turrets until something is happen in the game).
i saw that i can access GameEntity.Faction but faction are scripted objects. is there a public list of them any where?
i tried to create array of factions but it doesn't work...

thanks!

p.s: i didn't saw any scripting documents any where... are they exist some where online maybe?

haim.


Offline Nicolas

  • Administrator
  • Hero Member
  • *****
  • Posts: 792
Re: access game entity faction
« Reply #1 on: July 08, 2016, 11:33:10 AM »
Hi,

Sorry for the delay. Core Shooter Kit is still in Beta , so the API documentaiton is coming...

Faction are scriptable objet, the script that will change the faction need to have reference to the scriptable object.
Example :
Code: [Select]
using UnityEngine;
using System.Collections;
using HedgehogTeam.CoreShooterKit;

public class DynamicChangeFaction : MonoBehaviour {

public GameEntity entity2Change;
public Faction newFaction;

void Start(){
entity2Change.faction = newFaction;
}
}

Scriptable object are like other object, you have juste to drag and drop it from your project in the inspector




« Last Edit: July 08, 2016, 11:36:54 AM by Nicolas »

Offline haim

  • Newbie
  • *
  • Posts: 8
Re: access game entity faction
« Reply #2 on: July 10, 2016, 08:25:17 AM »
thanks for reply,

i tried something like this but i put several factions objects in array.
and when i tried to change faction i got nullreference error.

code was something like this:

Code: [Select]
using UnityEngine;
using System.Collections;
using HedgehogTeam.CoreShooterKit;

public class DynamicChangeFaction : MonoBehaviour {

public GameEntity entity2Change;
public Faction[] newFaction;

void Start(){
entity2Change.faction = newFaction[0];
}
}

(i didn't forgot to drag the factions to the array... of course...)

Offline Nicolas

  • Administrator
  • Hero Member
  • *****
  • Posts: 792
Re: access game entity faction
« Reply #3 on: July 11, 2016, 12:14:45 PM »
Can y ou give me the error raise by Unity ?

Have you setup entity2Change field in the inspector ?