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 Slendyberkay · Dec 07, 2013 at 07:47 PM ·

Need Help with rebuildable barricade system like in Call Of Duty Zombies

so this is what I need. I don't know much about programming stuff and need help with a script like this. Please don't get angry I just want ideas or suggestions about how can I make something like this. Tutorials or Examples accepted :D I really need some help. Thanks. Edit : Umm, I think i solved it myself but I am still having problems and i know what is my problem read the code please, i wrote something which will check barricade Health and teleport parts away. But as it is true it keeps teleporting parts away and i can't fix it. Edit2 : I solved that problem too, i still wonder if you can make a shorter version of this because this one lags a bit.

 #pragma strict //my old code
 @script RequireComponent( AudioSource )
 
 public var barricadeHealth : int = 0;
 
 public var thePlayer : Transform;
 
 public var theEnemy : Transform;
 
 public var barricade1a : Transform;
 
 public var barricade2a : Transform;
 
 public var barricade3a : Transform;
 
 public var barricade4a : Transform;
 
 public var barricade5a : Transform;
 
 var isBuilt : boolean = true;
 
 var canRepair : boolean = false;
 
 var attacking : boolean = false;
 
 var breaking : boolean = false;
 
 var canBreak : boolean = false;
  
 public var breakingSound : AudioClip;
 
 public var repairingSound : AudioClip;
  
 function Start() 
 {
     if ( thePlayer == null )
     {
        thePlayer = GameObject.Find( "Player" ).transform;
     }
     if ( theEnemy == null )
     {
        theEnemy = GameObject.Find( "Zombie" ).transform;
     }
 }
  
 function Update () {
 if (barricadeHealth<0)
 {
     barricadeHealth=0;
     isBuilt=false;
     breaking=false;
 } 
 if (barricadeHealth>0)
 {
     isBuilt=true;
 }
 if (breaking && canBreak)
 {
     Breaking();
 }
 if(isBuilt)
 
 {
     if(barricadeHealth>5)
     {
         barricadeHealth=5;
     }
     if(barricadeHealth==4)
     {
         
         barricade5a.transform.Translate(0,-10,0);
         if(Input.GetKeyUp(KeyCode.E) && isBuilt && canRepair)
         {
         barricade5a.transform.Translate(0,10,0);
         isBuilt = true;
         audio.PlayClipAtPoint( repairingSound, thePlayer.position );
         barricadeHealth+=1;
         }
     }
     if(barricadeHealth==3)
     {
         
         barricade4a.transform.Translate(0,-10,0);
         if(Input.GetKeyUp(KeyCode.E) && isBuilt && canRepair)
         {
         barricadeHealth+=1;
         isBuilt = true;
         audio.PlayClipAtPoint( repairingSound, thePlayer.position );
         barricade4a.transform.Translate(0,10,0);
         }
     }
     if(barricadeHealth==2)
     {
         
         barricade3a.transform.Translate(0,-10,0);
         if(Input.GetKeyUp(KeyCode.E) && isBuilt && canRepair)
         {
         barricadeHealth+=1;
         isBuilt = true;
         audio.PlayClipAtPoint( repairingSound, thePlayer.position );
         barricade3a.transform.Translate(0,10,0);
         }
     }
     if(barricadeHealth==1)
     {
         
         barricade2a.transform.Translate(0,-10,0);
         if(Input.GetKeyUp(KeyCode.E) && isBuilt && canRepair)
         {
         barricadeHealth+=1;
         isBuilt = true;
         audio.PlayClipAtPoint( repairingSound, thePlayer.position );
         barricade2a.transform.Translate(0,10,0);
         }
     }
 }
 if(!isBuilt)
     //if barricadeHealth equals 0
     barricade1a.transform.Translate(0,-10,0);
     if(Input.GetKeyUp(KeyCode.E) && !isBuilt && canRepair)
     {
         
         isBuilt = true;
         audio.PlayClipAtPoint( repairingSound, thePlayer.position );
         barricade1a.transform.Translate(0,10,0);
         barricadeHealth+=1;
     }
 }
 
 function OnTriggerEnter (other : Collider)
 {
         if(other.gameObject.name == "Player")
         {
                 canRepair = true;
                 if(other.gameObject.name == "Zombie")
                 {
                         breaking = true;
                 }
                 else
                 {
                         breaking = false;
                         attacking = true;
                 }
         }
 }
  
 function OnTriggerExit (other : Collider)
 {
         if(other.gameObject.name == "Player")
         {
                 canRepair = false;
                 if(other.gameObject.name == "Zombie")
                 {
                     breaking = false;
                 }
                 else
                 {
                     breaking = true;
                     attacking = false;
                 }
         }
 }
 
 function Breaking()
 {
     canBreak=false;
     yield WaitForSeconds (5);
     barricadeHealth-=1;
     audio.PlayClipAtPoint( breakingSound, theEnemy.position );
     canBreak=true;
     if (barricadeHealth>0)
     {
     isBuilt=true;
     }
 }







///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

 #pragma strict 
 //new working code

 @script RequireComponent( AudioSource )
 
 public var barricadeHealth : int = 0;
 
 public var thePlayer : Transform;
 
 public var theEnemy : Transform;
 
 public var barricade1a : Transform;
 
 public var barricade2a : Transform;
 
 public var barricade3a : Transform;
 
 public var barricade4a : Transform;
 
 public var barricade5a : Transform;
 
 var isBuilt : boolean = true;
 
 var canRepair : boolean = false;
 
 var attacking : boolean = false;
 
 var breaking : boolean = false;
 
 var canBreak : boolean = false;
  
 public var breakingSound : AudioClip;
 
 public var repairingSound : AudioClip;
  
 var barricadeDown1a : boolean = false;
 
 var barricadeDown2a : boolean = false;
 
 var barricadeDown3a : boolean = false;
 
 var barricadeDown4a : boolean = false;
 
 var barricadeDown5a : boolean = false;
 
 function Start() 
 {
     isBuilt = true;
     barricadeDown1a = false;
     
     if ( thePlayer == null )
     {
        thePlayer = GameObject.Find( "Player" ).transform;
     }
     if ( theEnemy == null )
     {
        theEnemy = GameObject.Find( "Zombie" ).transform;
     }
 }
  
 function Update () {
 if (barricadeHealth<0 || barricadeHealth==0)
 {
     barricadeHealth=0;
     isBuilt=false;
     breaking=false;
     
     //note that there is no barricadeDown1a = true; because it causes a bug in script
 
     barricadeDown2a = true;
 
     barricadeDown3a = true;
 
     barricadeDown4a = true;
         
     barricadeDown5a = true;
 } 
 if (barricadeHealth>0)
 {
     isBuilt=true;
 }
 if (breaking && canBreak)
 {
     Breaking();
 }
 if(isBuilt)
 
 {
     if(barricadeHealth>5 || barricadeHealth==5)
     {
         barricadeHealth=5;
         
         barricadeDown1a = false;
 
         barricadeDown2a = false;
 
         barricadeDown3a = false;
 
         barricadeDown4a = false;
         
         barricadeDown5a = false;
     }
     if(barricadeHealth==4)
     {
         barricadeDown1a = false;
 
         barricadeDown2a = false;
 
         barricadeDown3a = false;
 
         barricadeDown4a = false;
         if (!barricadeDown5a)
         {
             barricade5a.transform.Translate(0,-10,0);
             barricadeDown5a = true;
         }
         if(Input.GetKeyUp(KeyCode.E) && isBuilt && canRepair)
         {
         barricade5a.transform.Translate(0,10,0);
         isBuilt = true;
         audio.PlayClipAtPoint( repairingSound, thePlayer.position );
         barricadeHealth+=1;
         }
     }
     if(barricadeHealth==3)
     {
         barricadeDown1a = false;
 
         barricadeDown2a = false;
 
         barricadeDown3a = false;
         
         barricadeDown5a = true;
         
         if (!barricadeDown4a)
         {
             barricade4a.transform.Translate(0,-10,0);
             barricadeDown4a = true;
         }
         if(Input.GetKeyUp(KeyCode.E) && isBuilt && canRepair)
         {
         barricadeHealth+=1;
         isBuilt = true;
         audio.PlayClipAtPoint( repairingSound, thePlayer.position );
         barricade4a.transform.Translate(0,10,0);
         }
     }
     if(barricadeHealth==2)
     {
         barricadeDown1a = false;
 
         barricadeDown2a = false;
         
         barricadeDown4a = true;
         
         barricadeDown5a = true;
 
         if (!barricadeDown3a)
         {
             barricade3a.transform.Translate(0,-10,0);
             barricadeDown3a = true;
         }
         
         if(Input.GetKeyUp(KeyCode.E) && isBuilt && canRepair)
         {
         barricadeHealth+=1;
         isBuilt = true;
         audio.PlayClipAtPoint( repairingSound, thePlayer.position );
         barricade3a.transform.Translate(0,10,0);
         }
     }
     if(barricadeHealth==1)
     {
         barricadeDown1a = false;
         
         barricadeDown3a = true;
 
         barricadeDown4a = true;
         
         barricadeDown5a = true;
         
         if (!barricadeDown2a)
         
         {
             barricade2a.transform.Translate(0,-10,0);
             barricadeDown2a = true;
         }
 
         if(Input.GetKeyUp(KeyCode.E) && isBuilt && canRepair)
         {
         barricadeHealth+=1;
         isBuilt = true;
         audio.PlayClipAtPoint( repairingSound, thePlayer.position );
         barricade2a.transform.Translate(0,10,0);
         }
     }
 }
 if(!isBuilt)
     //if barricadeHealth equals 0
     if (!barricadeDown1a)
     {
         barricade1a.transform.Translate(0,-10,0);
         barricadeDown1a = true;
     }
     if(Input.GetKeyUp(KeyCode.E) && !isBuilt && canRepair)
     {
     
         isBuilt = true;
         audio.PlayClipAtPoint( repairingSound, thePlayer.position );
         barricade1a.transform.Translate(0,10,0);
         barricadeHealth+=1;
     }
 }
 
 function OnTriggerEnter (other : Collider)
 {
         if(other.gameObject.name == "Player")
         {
                 canRepair = true;
                 if(other.gameObject.name == "Zombie")
                 {
                         breaking = true;
                 }
                 else
                 {
                         breaking = false;
                         attacking = true;
                 }
         }
 }
  
 function OnTriggerExit (other : Collider)
 {
         if(other.gameObject.name == "Player")
         {
                 canRepair = false;
                 if(other.gameObject.name == "Zombie")
                 {
                     breaking = false;
                 }
                 else
                 {
                     breaking = true;
                     attacking = false;
                 }
         }
 }
 
 function Breaking()
 {
     canBreak=false;
     yield WaitForSeconds (5);
     barricadeHealth-=1;
     audio.PlayClipAtPoint( breakingSound, theEnemy.position );
     canBreak=true;
 }
 

alt text

untitled.png (230.5 kB)
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
0
Best Answer

Answer by Slendyberkay · Dec 08, 2013 at 04:52 PM

Any shorter version (İ learned that i can use gameObject enable/disable)

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

16 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 avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Multiple Cars not working 1 Answer

hide child object script - help 1 Answer

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

button question 1 Answer

Items with Statistics(such as attack damage) that actually effect the character? 2 Answers


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