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 /
  • Help Room /
avatar image
0
Question by Michealunity · Oct 27, 2015 at 07:16 PM · triggerissueupgradeproblem during runtime

OnTriggerStay problem or alternative mode

Hi guys, i'm an italian "programmer" i have a problem with my script. In few world i try to emulate LEAGUE OF LEGENDS tower functionality with my custom script and works at 80% more or less. The problem is that the difference between "LOL" and my idea is the runtime team change and for player and tower works when you change the team not in trigger, if you try to change when you are on the trigger this don't seems work. So if i have team1 change and select team2 not in trigger and the tower is set to attack only team1 when i re-enter on trigger the tower don't shoot me, if a change the team when i am into trigger the tower attack me ever if i keep team1,team2,team3. This is the script, i know that is more caotic but i hope in a help an maybe why not ,an upgrade of my script ;)


var team1 : boolean = false; var team2 : boolean = false; var team3 : boolean = false;

var target : GameObject; var minion : GameObject;

var minioninside : boolean = false;

var PlayerList : List. = new List.();

var oggetto : GameObject;

var MinionList : List. = new List.();

var reposizioning : boolean = false;

var numofplayer : int;

var numofminion : int;

function Start () { reposizioning = true; }

function Update () {

team1 = oggetto.gameObject.GetComponent(findenemy).team1; team2 = oggetto.gameObject.GetComponent(findenemy).team2; team3 = oggetto.gameObject.GetComponent(findenemy).team3;

numofminion = MinionList.Count; numofplayer = PlayerList.Count;

if(!target) { minioninside = true; }

if(numofminion <= 0) { minioninside = false; }

if(minioninside) { reposizioning = false; oggetto.transform.position = minion.transform.position; } else { if(target) { oggetto.transform.position = target.transform.position; } else { reposizioning = true; } }

if(minion.gameObject.GetComponentInParent(minionhealthbar).health <= 0) { MinionList.Remove(minion.gameObject); minion = null; }

if(!MinionList.Contains(minion.gameObject)) { minion = null; }

if(target.gameObject.GetComponentInParent(healthbar).health <= 0) { PlayerList.Remove(target.gameObject); target = null; }

if(!PlayerList.Contains(target.gameObject)) { target = null; } else {

 if(team1)

{ if(target.gameObject.GetComponentInParent(clicktomove).ally1) { target = null; } }

if(team2) { if(target.gameObject.GetComponentInParent(clicktomove).ally2) { target = null; } }

if(team3) { if(target.gameObject.GetComponentInParent(clicktomove).ally3) { target = null;
} }

}

for (var vita : GameObject in PlayerList) { if(vita.gameObject.GetComponentInParent(healthbar).health <= 0) { PlayerList.Remove(vita.gameObject);
} }

for (var mostro : GameObject in MinionList) { if(mostro.gameObject.GetComponentInParent(minionhealthbar).health <= 0) { MinionList.Remove(mostro.gameObject);
} }

if(team1) { if(target.gameObject.GetComponentInParent(clicktomove).ally1) { target = null; } }

if(team2) { if(target.gameObject.GetComponentInParent(clicktomove).ally2) { target = null; } }

if(team3) { if(target.gameObject.GetComponentInParent(clicktomove).ally3) { target = null;
} }

if(!target) { if(team1) { for(var one : GameObject in PlayerList) { if(!one.gameObject.GetComponentInParent(clicktomove).ally1) { target = one.gameObject; } } }

     if(team2)
     {
         for(var two : GameObject in PlayerList)
         {
             if(!two.gameObject.GetComponentInParent(clicktomove).ally2)
             {
                 target = two.gameObject;
             }
         }
     }
     
     if(team3)
     {
         for(var three : GameObject in PlayerList)
         {
             if(!three.gameObject.GetComponentInParent(clicktomove).ally3)
             {
                 target = three.gameObject;
             }
         }
     }
 }
 


}

function OnTriggerEnter (first : Collider) { if(first.gameObject.tag == "Cube") {

             if(first.gameObject.GetComponentInParent(healthbar).health > 0)
             {
                 if(!PlayerList.Contains(first.gameObject))
                 {
                     PlayerList.Add(first.gameObject);
                 }
                 
                 if(!target)
                 {
                     if(team1)
                         {
                             if(!first.gameObject.GetComponentInParent(clicktomove).ally1)
                             {
                             target = first.gameObject;
                             }
                         }
                 
                     if(team2)
                         {
                             if(!first.gameObject.GetComponentInParent(clicktomove).ally2)
                             {
                             target = first.gameObject;
                             }
                         }
                         
                     if(team3)
                         {
                             if(!first.gameObject.GetComponentInParent(clicktomove).ally3)
                             {
                             target = first.gameObject;
                             }
                         }
                 }
                 
             }
     }
 
 if(first.gameObject.tag == "minioncube")
     {
         if(first.gameObject.GetComponentInParent(minionhealthbar).health > 0)
         {
             if(!MinionList.Contains(first.gameObject))
             {
                 MinionList.Add(first.gameObject);
             }
         
             if(!minion)
             {
                 minion = first.gameObject;
             }
         }
     
         if(target == null)
         {
             minioninside = true;
         }
     
     
     }



}

function OnTriggerExit( third : Collider) {

 if(third.gameObject.tag == "Cube")
     {
         if(third.gameObject.GetComponentInParent(healthbar).health > 0)
         {
             if(PlayerList.Contains(third.gameObject))
             {
                 if(target == third.gameObject)
                 {
                     PlayerList.Remove(third.gameObject);
                     target = null;
                 }
                 else
                 {
                     PlayerList.Remove(third.gameObject);
                 }
             }
         }
     }
 
 if(third.gameObject.tag == "minioncube")
     {
         if(third.gameObject.GetComponentInParent(minionhealthbar).health > 0)
         {
             if(MinionList.Contains(third.gameObject))
             {
                 MinionList.Remove(third.gameObject);
             }
         }
     }

}


Thanks to all guys for every answer i receive

Cheers.

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

0 Replies

· Add your reply
  • Sort: 

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

32 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

Related Questions

Why when i change a scene things doesn't change? 0 Answers

How do I fix this problem? I already tried reinstallation. I cant enter playmode even on blank project 1 Answer

Unity won't start properly 0 Answers

Falling Object Trigger Problem 1 Answer

How to fix button triggers after upgrade to 5.2.3f1 Personal 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