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 ChrisSch · Jul 25, 2013 at 12:36 PM · collisiontagchangecheck

Tiny tag changing and checking problem

Hi y'all! No I'm not from Texas, fool'd ya right? Ok I'll shush, and get to the question. xD

Anyway here's the script. There's two objects, CargoPad_A and CargoPad_B script. This is CargoPad_A script but its pretty much the same as B. Anyway my problem is with this one.

What its suppose to do is when the player ship lands(collides) on it, check if it collided with a object with a tag "Player", change the player ships tag to "CargoPad_A_Loaded", change the CargoPad's tag to "CargoPad_A_Loaded" and give 500 score to the player(which is in another script), and thus rendering landing on the same pad twice or more, and getting score each time, not possible cause the ship is no longer tagged as "Player". But for some reason I can't figure out, the player gets 500 points if he lands on the same pad again even tho the tag changed, and then passes the level cause you only need 1000 points(load cargo on one pad, unload on another) to finish a level. xD

Already made a few levels with cargo pads, and I didn't notice earlier cause I played it right, and didn't land on the same pad twice. xD

 var stationLight : Light;
 var onMaterial : Material;
 var onColor : Color;
 
 var ship : GameObject;
 var shipScript : PlayerController;
 
 var GUI : InGameGUI;
 
 
 function Start ()
 {
     shipScript = ship.GetComponent(PlayerController);
     GUI = GameObject.FindWithTag("GUI").GetComponent(InGameGUI);
 }
 
 function OnCollisionEnter(cargoLoad : Collision)
 {
     if(cargoLoad.gameObject.tag == "Player")
     {
         shipScript.LoadCargoA();
         ship.gameObject.tag = "CargoPad_A_Loaded";
         Activate();
     }
     else if(cargoLoad.gameObject.tag == "CargoPad_A_Loaded")
     {
         print("Already loaded...");
     }
 }
 
 function Activate()
 {
     audio.Play();
     gameObject.tag = "CargoPad_A_Loaded";
     renderer.material = onMaterial;
     stationLight.color = onColor;
     GUI.LZActivated();
 }
Comment
Add comment · Show 6
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 dorpeleg · Jul 25, 2013 at 12:39 PM 0
Share

Can you share the part where you are giving out the points?

avatar image ChrisSch · Jul 25, 2013 at 12:47 PM 0
Share

Here its in the InGameGUI script. I don't think that's the problem, it just adds points when on collision enter, meaning when I land again, I just want it to change the tag of the player and pad so when I land on the same one again nothing happens. Would it maybe be simpler to disable the pad entirely once I land on it the first time? There isn't use for it after the first time anyway.

 function LZActivated()
 {
     levelScore+=500;
     scoreText.text = "score - "+levelScore;
     numActivated++;
     if(numActivated == totalLZ)
     {
         Win();
     }
 }
avatar image dorpeleg · Jul 25, 2013 at 12:49 PM 1
Share

Disabling is much more simple, but keep in $$anonymous$$d that disabling the object will make it disappear.

Did you check the players tag during run-time to make sure it really changes?

avatar image ChrisSch · Jul 25, 2013 at 12:56 PM 0
Share

I just did, when it lands, Ship changes its tag to CargoPad_A_Loaded, but the CargoPad never changes, it just remains as CargoPad_A as it is its starting tag.

The if(cargoLoad.gameObject.tag == "Player") does that check the tag of the ship which is colliding or the tag of the object holding that collider?

Also, ins$$anonymous$$d of disabling, can I just remove the script from it?

avatar image dorpeleg · Jul 25, 2013 at 01:05 PM 1
Share

It checks the object that collided.

What you are saying is that this line:

 gameObject.tag = "CargoPad_A_Loaded";


Is not doing it's job....

Do the rest of the stuff in Activate work?

Yes, you can remove the script using:

 Destroy(GetComponent(scriptname));
Show more comments

2 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by ChrisSch · Jul 25, 2013 at 03:02 PM

I fixed it. Rewrote most of the code and made new tags. Changed CargoPadA1 and CargoPadB2 to A1 and A2, cause the first was confusing me a lot. xD Also removed the light and material lines to make it simpler for viewing. I'll post both A1 pad and A2 pad's scripts if anyone needs them or had the same problems with tags. I commented on each line of A1.js to avoid future confusing when I forget how I did all that. xD

A1.js

 #pragma strict
 
 //Ship starts off with tag Player
 //Cargo pad A1 starts off with tag CargoPadA1
 
 var ship : GameObject;        //Ship we'll be accessing the code from to control the Cargo Loaded boolean.
 var shipScript : PlayerController; //Ship script we'll be changing the Cargo Loaded boolean.
 var GUI : InGameGUI; //GUI script we'll be using to get score from landing on CargoPadA1
 
 
 function Start ()
 {
     shipScript = ship.GetComponent(PlayerController);    //Get the PlayerController script from the ship
     GUI = GameObject.FindWithTag("GUI").GetComponent(InGameGUI);    //Get the InGameGUI script from the GUI object
     Debug.Log ("Connected to ShipsScript to control cargo load and to GUI for score");    //check if it reached this line
 }
 
 function OnCollisionEnter(cargoLoad : Collision)
 {
     if(cargoLoad.gameObject.tag == "Player") //Our initiate ship tag
     {
         Debug.Log ("Landed on A1"); //checking if we landed
         ship.gameObject.tag = "ShipLoaded"; //changing the ships tag to ShipLoaded so we can no longer land there as Player and get points
         Debug.Log ("Changed ships tag to ShipLoaded"); //checking
         Activate(); //Getting to function Activate. Purposfuly set in the middle of the code to check if it will work and everything after it
         gameObject.tag = "CargoPadALoaded"; //changing A1's tag to CargoPadALoaded, not necessary since we already changed the ships tag, but just in case
         Debug.Log ("Changed CargoPads script to CargoPadALoaded"); //checking
         shipScript.LoadCargoA();    //Just changing the cargoLoaded boolean to true in the PlayerController script
         Debug.Log ("Cargo loaded :)"); //checking if it reached to this point
     }
     else if(cargoLoad.gameObject.tag != "Player") //if the ship is no longer tagged Player, meaning it has cargo, nothing will happen upon collision
     {
         Debug.Log ("Already Landed on A1"); //checking if nothing happened
     }
 }
 
 function Activate()
 {
     audio.Play(); //playing audio to indicate that the ship has landed
     Debug.Log ("Playing audio."); 
     GUI.LZActivated(); //Giving score to the player in the InGameGUI script
 }

And A2.js

 #pragma strict
 
 //Cargo pad A2 starts off with tag CargoPadA2
 
 var ship : GameObject;
 var shipScript : PlayerController;
 var GUI : InGameGUI;
 
 function Start ()
 {
     shipScript = ship.GetComponent(PlayerController);
     GUI = GameObject.FindWithTag("GUI").GetComponent(InGameGUI);
 }
 
 function OnCollisionEnter(cargoLoad : Collision)
 {
     if(cargoLoad.gameObject.tag == "ShipLoaded")
     {
         Debug.Log ("Landed on A2");
         ship.gameObject.tag = "Player";
         Debug.Log ("Changed ships tag to Player");
         Activate();
         gameObject.tag = "CargoPadAUnloaded";
         Debug.Log ("Changed CargoPads script to CargoPadAUnloaded");
         shipScript.UnloadCargoA();
         Debug.Log ("Cargo unloaded :D");
     }
     else if(cargoLoad.gameObject.tag != "ShipLoaded")
     {
         Debug.Log ("Go back to A1 and load the cargo first!");
     }
 }
 
 function Activate()
 {
     audio.Play();
     Debug.Log ("Playing audio."); 
     GUI.LZActivated();
 }
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
avatar image
0

Answer by Seth-Bergman · Jul 25, 2013 at 01:20 PM

judging by your script, you never changed the cargo pad tag, just the ship:

 if(cargoLoad.gameObject.tag == "Player")
 {
 shipScript.LoadCargoA();
 ship.gameObject.tag = "CargoPad_A_Loaded";   //change this
 cargoLoad.gameObject.tag = "CargoPad_A_Loaded";   // to this
 Activate();
 }
Comment
Add comment · Show 1 · 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 ChrisSch · Jul 25, 2013 at 01:43 PM 0
Share

Didn't I change it with:

gameObject.tag = "CargoPad_A_Loaded";

In Activate()?

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

17 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

Related Questions

OverlapSphere, check how many object with specific tag did it collide with.. 2 Answers

Create tag in script, then check for it in collision 1 Answer

Need Extremely Specific Collision Detection (2D) 2 Answers

OnTriggerEnter2D is not working 1 Answer

Is there something like clicked.gameObject? 3 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