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
-1
Question by Bonkahe · Oct 17, 2013 at 12:13 AM · arrayinventoryadd

Inventory array add error

Well I've used this exact command before and I never recieved an error so I assume its somewhere else in the script.

The Error:

 Assets/Scripts/BaseGirlControl.cs(121,64): error CS1061: Type `UnityEngine.GameObject[]' does not contain a definition for `Add' and no extension method `Add' of type `UnityEngine.GameObject[]' could be found (are you missing a using directive or an assembly reference?)



The Code.

 using UnityEngine;
 using System.Collections;
 
 [AddComponentMenu("Camera-Control/Mouse Look")]
 public class BaseGirlControl : MonoBehaviour {
     // Health & Heat
     
     public int maxhealth = 100;
     public int curhealth = 100;
     private float healthbarlength;
     
     public int maxheat = 100;
     public int curheat = 100;
     private float heatbarlength;
     
     public Transform GameController;
     
     
     // movement
     
     public float animSpeed = 1.5f;
     public float speed = 10.0f;
     public float RotationSpeed = 100;
     private Animator anim;
     
     // in hand items
     
     public string pickupTag;
     private Transform pickuploc;
     private Transform rightPalmloc;
     private bool RightHandEquip;
     public bool collideweapon;
     
     // Non in-hand items
     
     private RaycastHit hit;
     private Ray ray;
     private bool rendermenu;
     
     public GameObject[] InventorySlots = new GameObject[3];
     
     // Use this for initialization
     void Start () {
         pickupTag = null;
         anim = GetComponent<Animator>();    
         RightHandEquip = false;
         collideweapon = false;
     }
 
     
     // Update is called once per frame
     void Update () {
         HandlesGUI hg = (HandlesGUI)GameController.GetComponent("HandlesGUI");
         if (hg.Rendermenu == true)
         {
             rendermenu = true;
         }
         else
         {
             rendermenu = false;
         }
         AddjustCurrentHealth(0);
         AddjustCurrentHeat(0);
         float h = Input.GetAxis("Horizontal");
         float v = Input.GetAxis("Vertical");
         anim.SetFloat("Speedz", v);            
         anim.SetFloat("Speedx", h);
         anim.speed = animSpeed;
         if (Input.GetMouseButton(1)) 
         {
         }
         else
         {
             if(rendermenu == false)
             {
                 transform.Rotate(0, Input.GetAxis("Mouse X"), 0 * Time.deltaTime * speed);
             }
         }
         
         
         
         // Handles weapons / In hand items
         
         
         if (Input.GetButton("InteractionKey"))
         {
             if (collideweapon == true)
             {
                 if (pickupTag != null)
                 {
                     pickuploc = GameObject.FindWithTag(pickupTag).transform;
                     pickuploc.GetComponent<WeaponControl>().ispickedup = true;
                     rightPalmloc = GameObject.FindWithTag("GrippingHand").transform;
                     pickuploc.transform.parent = rightPalmloc.transform;
                     RightHandEquip = true;
                 }
             }
         }
         if (Input.GetButton("DropWeaponKey"))
         {
             if (RightHandEquip == true)
             {
                 pickuploc = GameObject.FindWithTag(pickupTag).transform;
                 pickuploc.GetComponent<WeaponControl>().ispickedup = false;
                 RightHandEquip = false;
             }
         }
         
         // Handles Clicking in gui mode to pick up items
         
         if(rendermenu == true)
         {
             ray = Camera.main.ScreenPointToRay(Input.mousePosition);
             if(Input.GetButtonDown("Fire1"))
             {
                 if(Physics.Raycast(ray,out hit,20))
                 {
                     Debug.Log(hit.collider.tag);
                     if(hit.collider.tag == "Item")
                     {
                         InventorySlots.Add(hit.collider.gameObject);
                     }
                 }
             }    
         }
     }
     void OnGUI ()
     {
         // Health system
         if (rendermenu == true)
         {
             GUI.Box(new Rect(10, 10, 120, 20), "Health");
             GUI.Box(new Rect(10, 30, healthbarlength, 20), curhealth + "/" + maxhealth);
             
             GUI.Box(new Rect(10, 50, 120, 20), "Heat");
             GUI.Box(new Rect(10, 70, heatbarlength, 20), curheat + "/" + maxheat);
         }
     }
     
     // Health system
     
     public void AddjustCurrentHealth(int adj) {
         curhealth += adj;
     
         if(curhealth < 0)
             curhealth = 0;
         
         if(curhealth > maxhealth)
             curhealth = maxhealth;
         
         if(maxhealth < 1)
             maxhealth = 1;
         
         healthbarlength = (Screen.width / 2) * (curhealth / (float)maxhealth);
         
         if(curhealth == 0)
             Application.LoadLevel("MainMenu");
     }
     
     public void AddjustCurrentHeat(int adjh) {
         curheat += adjh;
     
         if(curheat < 0)
             curheat = 0;
         
         if(curheat > maxheat)
             curheat = maxheat;
         
         if(maxheat < 1)
             maxheat = 1;
         
         heatbarlength = (Screen.width / 2) * (curheat / (float)maxheat);
         
         if(curheat == 0)
             Debug.Log("Heatcold");
     }
 }


Second stupid question today, sorry guys this will be my last. Thanks allot, I apologize for the trouble.

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
2
Best Answer

Answer by robertbu · Oct 17, 2013 at 12:17 AM

InventorySlots ia array which doesn't have an 'Add' method. The 'Add' method is in .NET Lists. So make this work you would declare InventorySlots like this on line 40:

 public List<GameObject> InventorySlots = new List<GameObject>();

And at the top of the file:

 using System.Collections.Generic;
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 Bonkahe · Oct 17, 2013 at 02:02 AM 0
Share

The only problem with that, and the reason why I used arrays in the first place was I didn't want it to add it to the end of the list, thus making it longer, I wanted to use up one of the 3 slots, then when dropping it empty out said slot. Is there no way to use arrays? or make a list behave in this manner?

avatar image Bonkahe · Oct 17, 2013 at 02:14 AM 0
Share

Ok I got it working, thanks man!

avatar image robertbu · Oct 17, 2013 at 02:33 AM 1
Share

I'm not sure how you solved your problem. With an array, you can just assign a slot.

 InventorySlots[2] = something;
avatar image Bonkahe · Oct 17, 2013 at 01:29 PM 0
Share

Basically I just made a list that when I try to add an item if it = 3 it wont let you add anymore, simple enough, thanks anyways

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

14 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

Related Questions

C# Adding to an Array 1 Answer

Need help with array script 1 Answer

Lists, Is a type but is used like a variable Problem C# 1 Answer

How to set array length in unity USING C# 1 Answer

Help adding transform to end of array 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