Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 EliteHedgehog56 · Apr 26, 2018 at 03:26 AM · collisiontriggersscore systempoints

domination capture points

I am wanting to make a domination/king of the kill game mode in my splitscreen fps. How would I go about creating control points using colliders that change color depending on which player captured it and slowly add points to a player's score counter when all points are capture or if the hill is controlled?

Comment
Add comment · Show 4
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
avatar image KittenSnipes · Apr 26, 2018 at 03:28 AM 0
Share

@EliteHedgehog56

Would this be a 3d or 2d game?

avatar image EliteHedgehog56 KittenSnipes · Apr 26, 2018 at 03:34 AM 0
Share

@$$anonymous$$ittenSnipes it's a Splitscreen FPS so yeah it's a 3d game

avatar image EliteHedgehog56 EliteHedgehog56 · Apr 26, 2018 at 03:40 AM 1
Share

@$$anonymous$$ittenSnipes the easiest way I can think of in terms of capturing control points is by using a collider component and make it a trigger

Show more comments

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by KittenSnipes · Apr 26, 2018 at 04:51 AM

@EliteHedgehog56

Here is a nice script with comments explaining what each piece of code does.

     [Header("Name Of The Red Team")]
     public string redTeam = "Red";

     [Header("Name Of The Blue Team")]
     public string blueTeam = "Blue";
 
     //Materials To Change The Capture Point To
     public Material redCapColor;
     public Material blueCapColor;
 
     [Header("Time It Takes To Capture The Point")]
     public float CaptureTime = 5;
 
     [Header("Radius In Which The Point Is Capturable")]
     public float CapRadius = 5;
 
     //Time the team has held the capture point
     public float redCapture;
     public float blueCapture;
 
     //Empty Collider Array
     Collider[] colliders;
 
     //Radius to hold the statuses of the teams
     bool redCaptureStatus;
     bool blueCaptureStatus;
 
     void Start()
     {
         //Both of the teams capture status at the start are false
         blueCaptureStatus = false;
         redCaptureStatus = false;
 
         //Both of the teams capture times are 0 at the start
         redCapture = 0;
         blueCapture = 0;
     }
 
     void Update()
     {
         //Get the colliders inside the origin of this gameobject and the radius(CapRadius)
         colliders = Physics.OverlapSphere(transform.position, CapRadius);
 
         //If there is a collider detected within the radius(CapRadius)
         if (colliders.Length > 0 && colliders != null)
         {
             //Then loop through the colliders
             for (int i = 0; i < colliders.Length; i++)
             {
                 //Check if the Team Counts are not equal to each other
                 if (TeamCount(blueTeam, colliders) != TeamCount(redTeam, colliders) || TeamCount(redTeam, colliders) != TeamCount(blueTeam, colliders))
                 {
                     //If the collider within the circle is of the blue team
                     if (colliders[i].tag == blueTeam)
                     {
                         //And the teams capture time is less than the time it takes to capture
                         if (blueCapture < CaptureTime)
                         {
                             //Add to the teams capture time
                             blueCapture += Time.deltaTime;
 
                             //If the enemy teams capture time is greater than 0
                             if (redCapture > 0)
                             {
                                 //Subtract the enemy teams capture time
                                 redCapture -= Time.deltaTime;
                             }
                         }
 
                         //Else the teams capture time is greater than the capture time
                         else
                         {
                             //Set the capture status of the team to true and the enemys team to false
                             blueCaptureStatus = true;
                             redCaptureStatus = false;
                         }
                     }
 
                     //Check if the Team Counts are not equal to each other
                     else if (colliders[i].tag == redTeam)
                     {
                         //If the collider within the circle is of the red team
                         if (redCapture < CaptureTime)
                         {
                             //Add to the teams capture time
                             redCapture += Time.deltaTime;
 
                             //If the enemy teams capture time is greater than 0
                             if (redCapture > 0)
                             {
                                 //Subtract the enemy teams capture time
                                 blueCapture -= Time.deltaTime;
                             }
                         }
 
                         //Else the teams capture time is greater than the capture time
                         else
                         {
                             //Set the capture status of the team to true and the enemys team to false
                             redCaptureStatus = true;
                             blueCaptureStatus = false;
                         }
                     }
                     Debug.Log("Capturing...");
                 }
             }
         }
 
         //If the teams capture status is equal to true then set the color of our capture point accordingly
         if (redCaptureStatus == true)
         {
             GetComponent<Renderer>().material = redCapColor;
         }
 
         if (blueCaptureStatus == true)
         {
             GetComponent<Renderer>().material = blueCapColor;
         }
     }
     
     //Uses Team Tag and Collider Array To Find The Team Count
     int TeamCount(string tag, Collider[] colliders)
     {
         //Set the count to 0
         int count = 0;
 
         //Loop through the colliders array
         for (int i = 0; i < colliders.Length; i++)
         {
             //If the collider's tag within the array equal the team tag
             if (colliders[i].tag == tag)
             {
                 //Add to the count
                 count += 1;
             }
         }
         //Then return the complete count of the tag within the array
         return count;
     }
Comment
Add comment · Show 3 · 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
avatar image EliteHedgehog56 · Apr 26, 2018 at 04:58 AM 0
Share

@$$anonymous$$ittenSnipes cool, I'll give this a try and I'll get back to you :P

avatar image KittenSnipes EliteHedgehog56 · Apr 26, 2018 at 04:59 AM 0
Share

@EliteHedgehog56 Awesome :D

avatar image KittenSnipes EliteHedgehog56 · Apr 26, 2018 at 05:08 AM 0
Share

@EliteHedgehog56 Oh and make sure to tag your players as either red or blue to get anything to happen

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

128 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 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 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 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 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 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 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 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

Resizing colliders and OnTriggerEnter 0 Answers

Activate trigger if items colected 1 Answer

OnCollisionEnter When isTrigger = false 3 Answers

Scoring/Counting how many specific objects are placed on a specific plane. 1 Answer

Ignore collisions with self but still trigger with self 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