- Home /
Attack Script problem please help
My Problem is that i need to acces PlayerDamage.cs with the ZombieDamage.js as when the folowing script runs my hp drops im new to scripting and i cant understand the logic between those two c# to c# i can understand but java to c# its more complicated for mee
var maximumHitPoints = 100.0;
var hitPoints = 100.0;
var deadReplacement : Rigidbody;
var GOPos : GameObject;
private var ikilled = false;
function Start(){
}
function ApplyDamage (damage : float) {
if (hitPoints <= 0.0)
return;
// Apply damage
hitPoints -= damage;
// Are we dead?
if (hitPoints <= 0.0)
{
ikilled = true;
Replace();
//tell the networkplayer imdead
networkView.RPC("tellimdead", RPCMode.All);
}
}
function Replace() {
// If we have a dead barrel then replace ourselves with it!
if (deadReplacement) {
var dead : Rigidbody = Instantiate(deadReplacement, GOPos.transform.position, GOPos.transform.rotation);
// For better effect we assign the same velocity to the exploded barrel
dead.rigidbody.velocity = rigidbody.velocity;
dead.angularVelocity = rigidbody.angularVelocity;
}
// Destroy ourselves
Destroy(gameObject);
}
@RPC
function tellimdead()
{
//the networkplayer shouldn't get our score
ikilled = false;
Replace();
}
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class PlayerDamage : Photon.MonoBehaviour {
public GUISkin guiSKin;
//Player health
public float hp = 100;
public GameObject ragdoll;
public Texture2D bloodyScreen;
public Texture2D hitMarkTexture;
//Hitboxes and damage properties for each
[System.Serializable]
public class HitBoxes {
public Collider box /*{ get; set; } */;
public float damage /*{ get; set; }*/;
public HitBoxes(Collider box1, float damage1){
box = box1;
damage = damage1;
}
}
public List<HitBoxes> hitBoxes = new List<HitBoxes>();
[HideInInspector]
public float currentHp;
Quaternion camRot;
Quaternion camDefaultRotation;
//Fade hit mark
float fadeValue;
//Fade bloody screen
float fadeValueB;
void Awake(){
camDefaultRotation = Camera.main.transform.localRotation;
currentHp = hp;
if(!photonView.isMine){
for(int i = 0; i < hitBoxes.Count;i++){
hitBoxes[i].box.gameObject.AddComponent<HitBox>();
hitBoxes[i].box.gameObject.GetComponent<HitBox>().maxDamage = hitBoxes[i].damage;
hitBoxes[i].box.gameObject.GetComponent<HitBox>().playerDamage = this;
hitBoxes[i].box.isTrigger = true;
}
}else{
for(int a = 0; a < hitBoxes.Count;a++){
//We dont need our hit boxes, destroy them
Destroy (hitBoxes[a].box.collider);
}
hitBoxes.Clear();
}
}
public void totalDamage(float damage){
fadeValue = 2;
photonView.RPC("doDamage", PhotonTargets.All, damage);
if(weKilled){
GameObject.FindWithTag("Network").SendMessage("AddKillNotification", gameObject.name, SendMessageOptions.DontRequireReceiver);
}
}
bool weKilled;
[RPC]
void doDamage(float damage){
if(weKilled)
return;
if(currentHp > 0 && photonView.isMine){
this.StopAllCoroutines();
StartCoroutine(doCameraShake());
}
fadeValueB = 2;
currentHp -= damage;
//We got killed
if(currentHp < 0){
GameObject temp;
temp = Instantiate(ragdoll, transform.position, transform.rotation) as GameObject;
gameObject.SetActiveRecursively(false);
gameObject.active = true;
if(photonView.isMine){
print ("We got killed");
foreach(PhotonView p in transform.GetComponentsInChildren<PhotonView>()){
PhotonNetwork.RemoveRPCs(p);
}
temp.SendMessage("RespawnAfter");
StartCoroutine(photonDestroy());
}else{
temp.SendMessage("clearCamera");
}
currentHp = 0;
weKilled = true;
}
}
IEnumerator photonDestroy(){
yield return new WaitForSeconds(0.1f);
PhotonNetwork.Destroy(gameObject);
}
void OnGUI(){
//Display HP for our player only
if(photonView.isMine){
GUI.skin = guiSKin;
GUI.color = new Color(1,1,1,0.9f);
GUI.depth = 10;
GUI.color = new Color(1,1,1,fadeValueB);
GUI.DrawTexture(new Rect(0, 0, Screen.width, Screen.height), bloodyScreen, ScaleMode.StretchToFill );
GUI.color = new Color(1,1,1,0.9f);
//Display player hp
GUI.Box (new Rect (Screen.width - 220,Screen.height - 55,100,45), "HP | " + (int)currentHp);
}else{
GUI.color = new Color(1,1,1, fadeValue);
GUI.DrawTexture(new Rect(Screen.width/2 - 13, Screen.height/2 - 13, 26, 26), hitMarkTexture, ScaleMode.StretchToFill );
}
}
IEnumerator doCameraShake(){
//Change shake amount here (Currently its 10)
camRot = Quaternion.Euler (Random.Range(-10, 10), Random.Range(-10, 10), 0);
yield return new WaitForSeconds(0.1f);
camRot = camDefaultRotation;
}
void Update(){
fadeValue = Mathf.Lerp(fadeValue, 0, Time.deltaTime*2);
fadeValueB = Mathf.Lerp(fadeValueB, 0, Time.deltaTime*2);
//Do camera shake effect
if(Camera.main)
Camera.main.transform.localRotation
= Quaternion.Slerp(Camera.main.transform.localRotation, camRot, Time.deltaTime * 15);
}
}
Comment
Answer by doublethink · Jan 17, 2013 at 10:55 PM
Keeping all of your scripts in the same language helps tremendously for these types of issues. Here is a handy tool from a developer named m2h to help you.
Your answer
Follow this Question
Related Questions
Zombie A.I path finding help 2 Answers
Damage trigger? 1 Answer
Zombie attack script help 1 Answer
Ai Zombie Melee Attack script. 5 Answers
My rockets don't do damage? 1 Answer