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 /
This question was closed Sep 05, 2015 at 08:39 AM by JanVog for the following reason:

Didn't get an answer in time

avatar image
0
Question by JanVog · Sep 03, 2015 at 05:22 PM · javascriptarrayobjectgenerichashtable

JS objects in Unityscript || BCE0048: Type 'Object' does not support slicing.

 #pragma strict
 
 import System.Collections.Generic;
 
 var speed : float;
 
 var shoot : KeyCode;
 
 private var gunSlot1Transform : Transform;
 private var gunSlot2Transform : Transform;
 
 private var gun1ReloadTime : float;
 private var gun2ReloadTime : float;
 private var lastShotTime : float;
 
 var weapons : Weapons;
 
 private var weapon1ObjectTransform : GameObject;
 private var weapon1FirePoint : Transform;
 private var weapon1Projectile : GameObject;
 
 private var equippedWeapons = new ArrayList();
 
 
 function Start () {
     gun1ReloadTime = weapons.Kanone.reload;
     
     gunSlot1Transform = this.transform.Find("GunSlot1");
     
     equipWeapon(weapons.Kanone);
     
 //    weapon1ObjectTransform = Instantiate(Resources.Load(weapons.Kanone.objectTransformPath, GameObject));
 //    weapon1ObjectTransform.transform.parent = this.transform;
 //    weapon1ObjectTransform.transform.position = gunSlot1Transform.position - weapon1ObjectTransform.transform.Find("ConnectionPoint").position;
 //    weapon1FirePoint = weapon1ObjectTransform.transform.Find("FirePoint");
 //    weapon1Projectile = weapon1ObjectTransform.transform.Find("FireballProjectile").gameObject;
 }
 
 function Update () {
 
     var mousePos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
     transform.rotation = Quaternion.LookRotation(Vector3.forward, mousePos - transform.position);
     
     var move = Vector3(Input.GetAxis("Horizontal"), Input.GetAxis("Vertical"), 0);
     transform.position += move * speed * Time.deltaTime;
     
     if (Input.GetKey (shoot)) {
         for(var i = 0; i < equippedWeapons.Count; i++){
             //if(Time.time - lastShotTime > gun1ReloadTime){
                 //var projectile = Instantiate(weapon1Projectile, weapon1FirePoint.position, this.transform.rotation * Quaternion(0,0,90,-90));
                 //projectile.SetActive(true); 
                 //lastShotTime = Time.time;
                 //DestroyProjectileAfterDelay(projectile);
                 
                 for(var weapon in equippedWeapons){
                     Debug.Log(weapon["weaponGameObject"]);
                 }
             //}
         }
     }
      
     
 }
 
 function DestroyProjectileAfterDelay(Projectile : GameObject, weapon : Weapon) {
     yield WaitForSeconds(weapon.rangeInSec);
     Destroy(Projectile);
  }
  
  function equipWeapon(weapon : Weapon) {
      var equippedWeapon : Dictionary.<String, GameObject> = new Dictionary.<String, GameObject>();
      equippedWeapon["weaponGameObject"] = Instantiate(Resources.Load(weapon.objectTransformPath, GameObject));
     equippedWeapon["weaponGameObject"].transform.parent = this.transform;
     equippedWeapon["weaponGameObject"].transform.position = gunSlot1Transform.position - equippedWeapon["weaponGameObject"].transform.Find("ConnectionPoint").position;
     equippedWeapon["firePoint"] = equippedWeapon["weaponGameObject"].transform.Find("FirePoint").gameObject;
     equippedWeapon["projectile"] = equippedWeapon["weaponGameObject"].transform.Find("FireballProjectile").gameObject;
     equippedWeapons.Add(equippedWeapon);
  }

I get this error: "Assets/scripts/Player.js(56,51): BCE0048: Type 'Object' does not support slicing."

I do understand what the error wants to tell me and I know there were many other guys who had similar issues but this error isn't my main problem.

My problem: I need to store several GameObjects in a List but also need to access them with a key (JS object), but as I heard there is no way to have objects in Unity. I just found Generic Dictionary, but the problem with this type is that I need to have a List (Array) of those Dictionaries and well at this point this error occures! I heard of Classes as Objects aswell but I am not sure how to use them!

Thanks for your help in advance!

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

0 Replies

  • Sort: 

Follow this Question

Answers Answers and Comments

29 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

Related Questions

Adding an object to an array of custom objects (JS) 1 Answer

[Solved - Mostly] Hashtables, Arrays, Json and Slicing 1 Answer

GameObject turns into Object in Array 1 Answer

Using arrays to randomly select an object 0 Answers

foreach a array inside a generic list 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