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 theboss214 · Jul 18, 2018 at 06:46 PM · activationreactivation

How can I use SetActive to set something active when colliding with something?

I am trying to get coins that were previously picked up to reappear when the player dies after colliding with spikes which kill the player(handled by another script). Help would be appreciated, thanks in advance.

script: using System.Collections; using System.Collections.Generic; using UnityEngine;

 public class CoinPickup : MonoBehaviour {
 
     public int pointsToAdd;
 
 
     void OnTriggerEnter2D(Collider2D other)
     {
         if (other.GetComponent<PlayerController>() == null)
             return;
 
         ScoreManager.AddPoints(pointsToAdd);
 
         gameObject.SetActive(false);
 
         if (other.gameObject.name == "spikes first")
             gameObject.SetActive(true);
     }
 
 
 }
 
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 Vilhien · Jul 18, 2018 at 07:23 PM

Right now from the look of it you've got this script setup on the coins themselves.

The collision for the player would make them setactive false, however..

the second if is saying if the coins collide with spikes first? If I'm reading this correct, you want that part of the script to be called from the player (more importantly checking for his collider hitting the spikes), and the gameObject set to a list (setting to active)..

Then when the player triggers set the whole list active.

Perhaps setup a tag for the coins, when triggered it makes every object with the tag setactive.

Call this in start after setting the objects to a tag you create called "Coins"

in start: coins = GameObject.FindGameObjectsWithTag("Coins");

Then set the setActive to happen for all objects with such.

You can find a similar setup here. Example here.

https://answers.unity.com/questions/429701/how-to-set-gameobjectfindgameobjectswithtag-to-set.html

Comment
Add comment · Show 4 · 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 theboss214 · Jul 18, 2018 at 07:52 PM 0
Share

I know this is a very noob question but what type of variable would it be? I.e. float, int ect.

avatar image Vilhien · Jul 18, 2018 at 07:58 PM 0
Share

for the coins, keep everything the same, but get rid of the part with the spikes.

For the player,

at the top it's going to need a gameObject[] coins;

that's a gameObject list called coins.

Then in start you'll need that part mentioned above. coins = GameObject.FindGameObjectsWithTag("Coins");

that would make the script on the player find all the coins in the start and add them to a list, as long as their tag is set to coins.

then on the same sort for the player,...

on void triggerenter2D(collider other) { if(other.tag="Coins") { foreach(gameObject go in Coins) {go.setActive(true); } }

Or something close to the effects.. Sorry I'm at work.. I can't get you specific code.

avatar image theboss214 Vilhien · Jul 18, 2018 at 09:57 PM 0
Share

Thank you so much I just tried it and it worked I had spent weeks trying to figure this out on my own to no avail. Again thank you.

avatar image Vilhien theboss214 · Jul 18, 2018 at 11:43 PM 0
Share

No problem..

And yes that happens BUT! and this is a big but..

Its GREAT when you get stuff to work on your on by trouble shooting, it instills confidence to be able to take on larger ideas and problems. I didn't know anything about unity a year ago, and like you I've struggled with many problems for weeks.. One thing I may suggest that I've read, and I try to follow.

Try to accomplish one thing a day for your game, albeit small or something you just think up. Here's the kicker, don't get stuck on something for too long. Projects like thoughts from the above can turn into a few days, weeks..

Next thing you know your trying to adjust spawn values for planets where their scale accidentally overlap suns, "gravity" (and I stress the " 's because my gravity is made up), and ter$$anonymous$$al velocity in 3D. But remember to try not to get stuck, because then its not as much fun. I've rambled too long. ~Back to figuring out planet spawn ranges from suns.

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

87 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

Related Questions

Account Activation 0 Answers

Manual/Offline Activation of Unity 3.x 12 Answers

Unity won't open, or go past blank license screen 0 Answers

is it Possible to Move a UI Slider remotely by script? If So How 1 Answer

How do I acitvate Unity? 0 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