Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 Natrx · Aug 27, 2020 at 03:22 PM · script.find

How to Find The Last Item To Use A Specific Script

Do you know if you can help me with my problem. I want to find the last item that used my itempickup script then instantiate it, This is a drop item system for my stickman game. The problem is if lets say i pickup a wood sword, all is great, but then when i go to pickup a iron sword, the iron sword is picked up but instead of instantiating the wood sword to the players position, it instantiates the iron sword. Thanks In Advance! So Heres the Code:

using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.SceneManagement; using UnityEngine.UI;

public class Itempickup : MonoBehaviour { using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.SceneManagement; using UnityEngine.UI;

public class Itempickup : MonoBehaviour {

 public GameObject Item;
 bool playerContact;
 public Transform Feet;
 public bool equippedOn;
 public GameObject ThisItem;
 public LayerMask Weapons;
 public GameObject LastItem;
 [SerializeField]
 private Text text;
   
 
   
 public void Start()
 {
      text.gameObject.SetActive(false);
 }


private void Update() { if (playerContact == true && Input.GetKeyDown(KeyCode.E)) {
GameObject[] ThisItem = GameObject.FindGameObjectsWithTag ("Weapons");

     foreach(GameObject go in ThisItem)
     {
         go.SetActive(false);
         Spawn();    
     }    

Equip();
}
}

void Equip() {

    Item.SetActive(true);
    //ThisItem.SetActive(false);
    Destroy(gameObject);
    equippedOn = true;


}

void Spawn()

{

 Instantiate(ThisItem, transform.position, Quaternion.identity);
 Debug.Log("Prefab Made" + ThisItem.name);    


}

void Drop() {

    Item.SetActive(false);
    ThisItem.SetActive(true);
    equippedOn = false;    



 

}

void OnTriggerEnter2D(Collider2D collision)
{

       if(collision.CompareTag("Pickup"))
       {


    playerContact = true;  

     text.gameObject.SetActive(true); 

         }




 }



 void OnTriggerExit2D(Collider2D collision)



{

  if (collision.CompareTag("Pickup"))
  playerContact = false;
   text.gameObject.SetActive(false);




   

}

}

Comment
Add comment · Show 2
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 ShadyProductions · Aug 28, 2020 at 10:08 AM 1
Share

If you want our help, can you atleast put in "some" effort into writing and rereading your questions that you post, you can clearly see your code is not formatted correctly. We will not put our effort in trying to help you, if you don't atleast put some effort into properly asking a question.

avatar image Natrx ShadyProductions · Aug 28, 2020 at 02:31 PM 0
Share

@ShadyProductions ok sure but the thing is that unity seperates the code really badly for no reason when all should be good so sorry if its hard to read im a beginner and i dont know why unity seperates so much. i redid the question above. Basically i want to instantiate the last item i picked up instead of the current one i picked up.

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

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

Script not Referencing deleted Text object. 1 Answer

How do I check a bool from another script?? 2 Answers

find sript which modifies property of gameobject in large scene 1 Answer

Variable Equivalent of GameObject.Find 1 Answer

Class Parameter of MonoScript throws error on build 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