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 RVDL_IT · May 03, 2017 at 04:13 PM · c#errorgameobjectsfindgameobjectswithtagcs1061

GameObject[] doesn't have a definition for transform/name/etc...

I have a pick up script that has GameObject[] for the code FindGameObjectsWithTag.

This is my script:

 using UnityEngine;
 using System.Collections;
 using CameraRayCastLine;
 using PickUpSphereCast;
 
 namespace CarryingItems {
 
     public class PickUp : MonoBehaviour {
         
         
         // The variables for the positions.
             // Forward drop offset.
                 public float OffsetDropPosition = 2;
                 
         // The boolean that checks if the camera's RayCast is hit.
             public bool CameraRayHit;
         
         // The Player and the tagged objects.
             public GameObject Camera;
             public GameObject[] CarryableObject;
             public GameObject Character;
             public Transform CharacterTransform;
             
         // Is an item picked up at the moment?
             public bool ItemPickedUp;
         
         // Are you in the item's SphereCast?
             public bool InItemSpherecast;
             
         // Are you looking at an item?
             public bool LookingAtObject;
         
         
         void Awake() {
             // The origin of the objects.
                 Camera = GameObject.Find("MainCamera");
                 CarryableObject = GameObject.FindGameObjectsWithTag("CarryableObjects");
                 Character = GameObject.Find("Character");
                 CharacterTransform = GameObject.Find("Character").transform;
             // The code that references the RayCast script of the camera.
                 CameraRayHit = Camera.GetComponent<CameraRayCastLine.PickUpRayCast>().CameraRayCast;
             // The code that references the SphereCast of another script.
                 InItemSpherecast = PickUpSphereCast.ItemPickUpSphereCast.ItemSphereCast;
         }
 
         void Start() {
             // The code that tells you how to pick up an object through the debug log.
                 Debug.Log("Press E to pick up an object.");
         }
         
         void Update() {
             
         }
         
         void PickUpItemCode() {
             // If another item isn't picked up at the moment.
                 if(ItemPickedUp == false) {
                     Debug.Log("No items picked up.");
                     // If you're in the SphereCast.
                         if(InItemSpherecast == true) {
                             Debug.Log("Spherecast = true.");
                             // If you're looking at the item.
                                 if (CameraRayHit == true) {
                                     // A boolean for the GUI.
                                         LookingAtObject = true;
                                     // A code that says you can pick up the item in question.
                                         Debug.Log("Press E to pick up the" + CarryableObject.name + ".");
                                     // If you press the E key.
                                         if (Input.GetKeyDown("e")) {
                                             // The position relative to the character.
                                                 CarryableObject.transform.position = new Vector3(Character.transform.position.x + 1, Character.transform.position.y + 1, Character.transform.position.z + 1);
                                             // The rotation relative to the character.
                                                 CarryableObject.transform.rotation = Character.transform.rotation;
                                             // The gravity.
                                                 CarryableObject.GetComponent<Rigidbody>().useGravity = false;
                                             // A message showing that the object was picked up.
                                                 Debug.Log("You picked up the " + CarryableObject.name + "! Good for you!");
                                                 Debug.Log("Press the left mouse button to use an object.");
                                                 Debug.Log("Press E to drop an object.");    
                                             // The code that acitvates the boolean that is needed for the dropping script.
                                                 ItemPickedUp = true;
                                             // The code that makes the chracter the new objects parent.
                                                 CarryableObject.transform.SetParent(CharacterTransform);
                                         }
                                 }
                                 else {
                                     // You're not looking at an object.
                                         LookingAtObject = false;
                                 }
                         }
                 }
                 else {
                     // The code that makes sure that the pick up boolean is not active when no item is picked up.
                         ItemPickedUp = false;
                 }
         }
 
         void DropItemCode() {
             // If you're holding an item.
                 if(ItemPickedUp == true){
                     // If you press the E key.
                         if(Input.GetKeyDown("e")){
                             // The drop position.
                                 CarryableObject.transform.position = new Vector3(CarryableObject.transform.position.x, CarryableObject.transform.position.y, CarryableObject.transform.position.z + OffsetDropPosition);
                             // The gravity gets reenabled.
                                 CarryableObject.GetComponent<Rigidbody>().useGravity = true;
                         }
                 }
         }
         
         void ONGUI() {
             if(LookingAtObject == true){
                 // The how to pick up items text.
                     GUI.Label(new Rect(500, 200, 100, 20), "Press E to pick up the" + CarryableObject + ".");
             }
         }
     }
 }
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

Answer by jdean300 · May 03, 2017 at 04:21 PM

GameObject[] is a whole set of objects. What you need to do is choose which one you want to access, something like this: CarryableObject[0].transform.position.

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 RVDL_IT · May 03, 2017 at 05:45 PM 0
Share

I want which gameobject is picked to be relevant to which one I'm trying to pick up. How do I do this using GameObject[]?

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

318 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image 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

Check if 2 or more objects of same type is near object. 1 Answer

Any ideas as to why I get this error? (CS1061) 1 Answer

The pickups aren't rotating on the spot, but around the screen. My player game object also isn't receiving input from my keyboard. What is going on? 0 Answers

Adjust the size of the object within a parent container 0 Answers

error CS0201 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