Points system.

Hello, Im working on a Zombie Game similar to Call of Duty type zombie game mode.
I have a map set up, along with my fps,fully working guns, and zombies that die when shot.

unfortunately i need to add a points system like a GUI text or something to stay on the players screen, displaying how many points they have obtained. (10 points per zombie)
i have also set up barriers in key points of the map where players cain’t travel through. I need to know

.How to add a points system along with GUI text.
.How to add 10 points to the players score when a zombie is killed.
. How to delete a barrier for set points while subtracting the points from players score like a “Cost” to remove the barrier.

If anyone could lead me towards the right direction on how achieve this is would be very grateful. sadly i don’t have much knowledge of scripting. so a full script would be very very very helpful. if its too much to ask for a script than a worded tutorial would also be very helpful.

Here is the script for the health and death for zombies (i don’t really know if this would help but…)

//Applies damage to NPCs
using UnityEngine;
using System.Collections;

public class CharacterDamage : MonoBehaviour {
public float hitPoints = 100.0f;
public Transform deadReplacement;
public AudioClip dieSound;
public bool removeBody;
public float bodyStayTime = 15.0f;
private Vector3 attackerPos2;
private Vector3 attackDir2;
private Transform myTransform;
//set ray mask to layer 9, the ragdoll layer
//for applying force to specific ragdoll limbs
private LayerMask raymask = 1 << 9;

void Start (){
myTransform = transform;
}
//damage NPC
public void ApplyDamage ( float damage, Vector3 attackDir, Vector3 attackerPos ){

if (hitPoints <= 0.0f){
return;
}

hitPoints -= damage;

attackDir2 = attackDir;
attackerPos2 = attackerPos;

//expand enemy search radius if attacked outside default search radius to defend against sniping
if(transform.GetComponent()){
transform.GetComponent().attackRange = transform.GetComponent().attackRange * 3;
}

if (hitPoints <= 0.0f){
SendMessage(“Die”);//use SendMessage() to allow other script components on this object to detect NPC death
}
}

void Die (){

RaycastHit rayHit;
// Play a dying audio clip
if (dieSound){
AudioSource.PlayClipAtPoint(dieSound, transform.position);
}

// Replace ourselves with the dead body
if (deadReplacement) {
Transform dead = Instantiate(deadReplacement, transform.position, transform.rotation) as Transform;

// Copy position rotation from the old hierarchy into the dead replacement
CopyTransformsRecurse(transform, dead);

//apply damage force to NPC ragdoll if being damaged by player
if(Physics.SphereCast(attackerPos2, 0.2f, attackDir2, out rayHit, 750.0f, raymask)
rayHit.rigidbody
attackDir2.x !=0){
//apply damage force to the ragdoll rigidbody hit by the sphere cast (can be any body part)
rayHit.rigidbody.AddForce(attackDir2 * 50.0f, ForceMode.Impulse);

}else{//apply damage force to NPC ragdoll if being damaged by an explosive object or other damage source without a specified attack direction

Component[ ] bodies;
bodies = dead.GetComponentsInChildren();
foreach(Rigidbody body in bodies) {
if(body.transform.name == “Chest”){//only apply damage force to the chest of the ragdoll if damage is from non-player source
//calculate direction to apply damage force to ragdoll
body.AddForce((myTransform.position - attackerPos2).normalized * 30.0f, ForceMode.Impulse);
}
}

}

//initialize the RemoveBody.cs script attached to the NPC ragdoll
if(dead.GetComponent()){
if(removeBody){
dead.GetComponent().enabled = true;
dead.GetComponent().bodyStayTime = bodyStayTime;//pass bodyStayTime to RemoveBody.cs script
}else{
dead.GetComponent().enabled = false;
}
}

Destroy(transform.gameObject);

}

}

static void CopyTransformsRecurse ( Transform src , Transform dst ){
dst.position = src.position;
dst.rotation = src.rotation;

foreach(Transform child in dst) {
// Match the transform with the same name
Transform curSrc = src.Find(child.name);
if (curSrc)
CopyTransformsRecurse(curSrc, child);
}
}
}

If someone is nice enough to make a script for Zombie/barrier delete i would ask if you make the barrier delete script customizable…for example

i have my barrier named “fallen log” so if i take the script and place it on the object. it would let me customize how much it costs to destroy it. (this is an extra thing but if its possible could you make text appear when you look at the log displaying its price.)

Again if this is too much to ask i would be fine if someone could show me how to do it :3
I’m mostly in need for the first script. so if you don’t feel like you want to do the other script that fine i would very appreciate it XD thanks a bunch :slight_smile:

Just tyring to make it easier to read

//Applies damage to NPCs 
using UnityEngine;
using System.Collections;

public class CharacterDamage : MonoBehaviour {
	public float hitPoints = 100.0f;
	public Transform deadReplacement;
	public AudioClip dieSound;
	public bool  removeBody;
	public float bodyStayTime = 15.0f;
	private Vector3 attackerPos2;
	private Vector3 attackDir2;
	private Transform myTransform;
	//set ray mask to layer 9, the ragdoll layer
	//for applying force to specific ragdoll limbs
	private LayerMask raymask = 1 << 9;
	
	void Start (){
		myTransform = transform;
	}
	//damage NPC
	public void ApplyDamage ( float damage, Vector3 attackDir, Vector3 attackerPos ){

		if (hitPoints <= 0.0f){
			return;
		}
		
		hitPoints -= damage;
		
		attackDir2 = attackDir;
		attackerPos2 = attackerPos;
		
		//expand enemy search radius if attacked outside default search radius to defend against sniping
		if(transform.GetComponent<AI>()){
			transform.GetComponent<AI>().attackRange = transform.GetComponent<AI>().attackRange * 3;
		}
		
		if (hitPoints <= 0.0f){
			SendMessage("Die");//use SendMessage() to allow other script components on this object to detect NPC death
		}
	}
	
	void Die (){
		
		RaycastHit rayHit;
		// Play a dying audio clip
		if (dieSound){
			AudioSource.PlayClipAtPoint(dieSound, transform.position);
		}
	
		// Replace ourselves with the dead body
		if (deadReplacement) {
			Transform dead = Instantiate(deadReplacement, transform.position, transform.rotation) as Transform;
	
			// Copy position  rotation from the old hierarchy into the dead replacement
			CopyTransformsRecurse(transform, dead);
			
			//apply damage force to NPC ragdoll if being damaged by player
			if(Physics.SphereCast(attackerPos2, 0.2f, attackDir2, out rayHit, 750.0f, raymask)
			 rayHit.rigidbody 
			 attackDir2.x !=0){
				//apply damage force to the ragdoll rigidbody hit by the sphere cast (can be any body part)
				rayHit.rigidbody.AddForce(attackDir2 * 50.0f, ForceMode.Impulse);
			
			}else{//apply damage force to NPC ragdoll if being damaged by an explosive object or other damage source without a specified attack direction
			
				Component[] bodies;
				bodies = dead.GetComponentsInChildren<Rigidbody>();
				foreach(Rigidbody body in bodies) {
					if(body.transform.name == "Chest"){//only apply damage force to the chest of the ragdoll if damage is from non-player source 
						//calculate direction to apply damage force to ragdoll
						body.AddForce((myTransform.position - attackerPos2).normalized * 30.0f, ForceMode.Impulse);
					}
				}
				
			}
			
			//initialize the RemoveBody.cs script attached to the NPC ragdoll
			if(dead.GetComponent<RemoveBody>()){
				if(removeBody){
					dead.GetComponent<RemoveBody>().enabled = true;
					dead.GetComponent<RemoveBody>().bodyStayTime = bodyStayTime;//pass bodyStayTime to RemoveBody.cs script
				}else{
					dead.GetComponent<RemoveBody>().enabled = false;
				}
			}
			
			Destroy(transform.gameObject);
			
		}
	
	}
	
	static void CopyTransformsRecurse ( Transform src , Transform dst ){
		dst.position = src.position;
		dst.rotation = src.rotation;
		
		foreach(Transform child in dst) {
			// Match the transform with the same name
			Transform curSrc = src.Find(child.name);
			if (curSrc)
				CopyTransformsRecurse(curSrc, child);
		}
	}
}

http://forum.unity3d.com/threads/143875-Using-code-tags-properly

Is this script attached to the zombie prefab?

Yes that code is attached to my zombie. i have other code that helps him move and fallow the player and whatnot but this code controls his damage from bullets/sword, its also the death script (turns into a rag doll and gradually disappears.

Everything looks low res and hard to see in this video (because of my crappy recorder)
but the concept is there :smile:

The zombies have high HP so i lowered it after i made this video.

Also there is sound in the game. but for some resin it didn’t go through the recording.

Trust me the actual gameplay resolution is really good (again just the recorder)
i recommend not watching it in full screen, than you’ll get a rough idea of how it looks in person.
another thing to note in this video is i didn’t use all of the guns. there are a lot more i just forgot to showcase them :frowning:

stop watching the video around 3:27 i was acting like a moron and couldn’t figure out how to turn the screen recorder off XD

To add to the player points when the zombie dies you can just have a variable in the game controller or a script attached to the player to hold the score like score then in the zombie script void Die () you just access this variable and add to it.

GUI’s to show the score are really easy, this video (not mine) show how to do it:

Removing a barrier based on points cost can be done by adding a script to each barrier prefab or gameobject with a variable to hold the cost, this script can call the players score and check the score and reduce the score by xx points the same way as the zombie script does.

I’m confused :frowning:
i don’t know the types of variables…i have know idea how to script.
would it be possible to write a small script such as

On zombie killed add 10 points to player score?

How have you managed to create the game you show in your video while “having no idea how to script”?

He didn’t

I use this script for quick-and-dirty “rising points” type displays, like CoD has.

using UnityEngine;
using System.Collections;

public class PointsDisplayer : MonoBehaviour
{
	public static GameObject Create( int points)
	{
		GameObject go = new GameObject();
		PointsDisplayer pd = go.AddComponent<PointsDisplayer>();
		pd.s = System.String.Format ( "+{0}", points);
		return go;
	}

	string s;		// points rendered and ready for display

	float age;
	const float ageLimit = 1.0f;

	void Update()
	{
		age += Time.deltaTime;
		if (age >= ageLimit)
		{
			Destroy( gameObject);
			return;
		}
	}

	void OnGUI()
	{
		Rect r = new Rect(
			Screen.width * 0.3f, Screen.height * (0.4f - (0.3f * age) / ageLimit),
			Screen.width * 0.4f, Screen.height * 0.1f);

		GUI.Label( r, s);
	}
}

Whenever points are awarded in the game, call it like so:

	PointsDisplayer.Create( 1234);	// however much score earned

Kurt