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