Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by cepoimario95 · Jan 17, 2013 at 03:22 PM · aidamagepathattackzombie

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
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
-1

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.

See http://files.m2h.nl//js_to_c.php

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

10 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges