Getting XP Script Help

Hi Guys :slight_smile: I have a Problem. I have a script that shall give the Player XP when the Enemy Dies. but it doesn’t give any XP. Any Solutions :)?
SCRIPT:

using UnityEngine;
using System.Collections;

public class EnemyHealth : MonoBehaviour {
public int maxHealth;
public int curHealth;
public int giveXP;
public GameObject destroy;

// Use this for initialization
void Start () {

}

// Update is called once per frame
void Update () {
	AddjustCurrentHealth(0);
}

public void AddjustCurrentHealth(int adj) {
	curHealth += adj;
	
	if(curHealth <= 0)
		Die();
	
	if(curHealth > maxHealth)
		curHealth = maxHealth;
	
	if(maxHealth < 1)
		maxHealth = 1;
	
}

public void Die () {
	Stats st = (Stats)GetComponent("Stats");
	st.XP += giveXP;
	curHealth = 0;
	Destroy(destroy);
}

}

So I guess your player has the stats script on him?

Try

Stats st = Gmeobject.Find("Player").GetComponent<Stats>();

st.XP += giveXP;

You could simply put on the enemy

function Start(){
  var player = GameObject.Find("Player");
  stats : Stats = player.GetComponent("Stats");}

function Update(){
  if(dies)
    stats.exp+=100;
}

Or as your exp is a single value, you can use static

on the player Stats.js

static var exp;

on the enemy

function Update(){
  if(dies)
    Stats.exp +=100;}