- Home /
Slicing Not Supported/Transform Not a Member Disaster
I just successfully completed a trial web version of my new Unity project. It works fine. The final deliverable however is an IOS platform game. Problem is, some of the web version code does not seem to translate to well to IOS. Here is my 'good' web player code.
var newball; static var tempBasketBall :Rigidbody;
var pos :Transform[0];
var ball1 :Rigidbody;
var ball2 :Rigidbody;
var ball3 :Rigidbody;
var canControl1 = true; var canControl2 = true; var canControl3 = true;
var destroyTime :int = 6;
var player1 :GameObject;
var player2 :GameObject;
var player3 :GameObject;
var b1Parent :Transform;
var b2Parent :Transform;
var b3Parent :Transform;
var yVel :float; var zVel :float;
function Start()
{ ball1 = Instantiate (tempBasketBall, pos[0].position, pos[0].rotation); ball1.transform.parent = b1Parent;
ball2 = Instantiate (tempBasketBall, pos[1].position, pos[1].rotation);
ball2.transform.parent = b2Parent;
ball3 = Instantiate (tempBasketBall, pos[2].position, pos[2].rotation);
ball3.transform.parent = b3Parent;
}
function Update() { if(Input.GetButtonDown("Player1") && canControl1) { player1.animation.PlayQueued("aim"); }
else if(Input.GetButtonUp("Player1") && canControl1)
{
player1.animation.PlayQueued("fire");
ball1.transform.parent = null;
ball1.useGravity = true;
ball1.velocity = transform.TransformDirection(0, yVel, zVel);
MakeBall1(pos[0]);
DestroyBall(ball1);
canControl1 = false;
player1.animation.PlayQueued("idle");
}
if(Input.GetButtonDown("Player2") && canControl2)
{
player2.animation.PlayQueued("aim");
}
else if(Input.GetButtonUp("Player2") && canControl2)
{
player2.animation.PlayQueued("fire");
ball2.transform.parent = null;
ball2.useGravity = true;
ball2.velocity = transform.TransformDirection(0, yVel, zVel);
MakeBall2(pos[1]);
DestroyBall(ball2);
canControl2 = false;
player2.animation.PlayQueued("idle");
}
if(Input.GetButtonDown("Player3") && canControl3)
{
player3.animation.PlayQueued("aim");
}
else if(Input.GetButtonUp("Player3") && canControl3)
{
player3.animation.PlayQueued("fire");
ball3.transform.parent = null;
ball3.useGravity = true;
ball3.velocity = transform.TransformDirection(0, yVel, zVel);
MakeBall3(pos[2]);
DestroyBall(ball3);
canControl3 = false;
player3.animation.PlayQueued("idle");
}
}
function MakeBall1(pos)
{ yield new WaitForSeconds(1); ball1 = Instantiate(tempBasketBall, pos.transform.position, pos.transform.rotation); ball1.transform.parent = b1Parent; canControl1 = true; }
function MakeBall2(pos) { yield new WaitForSeconds(1); ball2 = Instantiate(tempBasketBall, pos.transform.position, pos.transform.rotation); ball2.transform.parent = b2Parent; canControl2 = true; }
function MakeBall3(pos) { yield new WaitForSeconds(1);
ball3 = Instantiate(tempBasketBall, pos.transform.position, pos.transform.rotation);
ball3.transform.parent = b3Parent;
canControl3 = true;
}
function DestroyBall(ball:Rigidbody)
{
yield new WaitForSeconds(destroyTime);
Destroy(ball.gameObject);
}
I get a strange error saying add a semi colon at end when i add this code to my IOS build. Well clearly there is a semicolon there. It was suggested I get rid of the [0]....when I do that I get a, "BCE0048: Type 'UnityEngine.Transform' does not support slicing". If I get delete the slicing elements in the 'start function' I get this error; BCE0019: 'transform' is not a member of 'Object'. Removing 'transform' I get an error saying 'position' is not a member further degrading my control of the position of the instantiated new ball. How can I adapt this original code to work in IOS without giving up the position and transform of where the ball is to be cloned(the players Hand)? I butchered the code enough to make it compile, but the new ball instantiates at some arbitrary position and shoots from there, this is not acceptable. Any assistance would be greatly appreciated as I'm approaching a deadline and need to move pass this translation quirk.
Ok! Sorry about the formatting, I guess a site that is very similar does the, indent code by 4 spaces thingy. Confusion on top of confusion! So sorry
Answer by Owen-Reynolds · Nov 14, 2011 at 04:17 PM
The first array should "officially" look like var pos : Transform[];
. Says that pos will link up with some array, to be created later. The zero inside sort of says you want to create the array now, with zero things in it, before replacing it with the real array.
It's possible that your web platform ignored the zero inside -- but the iOS compiler is more strict about it. The missing semicolon message probably means "uh, I don't get this line, but if you moved the semicolon just after Transform, you could at least make the first part legal."
@Owen Reynolds Thanks man! That did clear up that first error. But the script is still not controlling where the ball is instantiated. Though the pos array for three players indicates that the right hand is the position and transform where the newball should clone, it creates it on the floor or units above his head and then changes positions the more one shoots. So it's not reading this setup at all. I've even made the ball a child of the right hand and it still creates it in some random position. Guess I'll scrap this template and start from scratch. If any one has any ideas on IOS instantiating from a defined position and shooting the projectile please let me know. I'm open to suggestions. Thanks
$$anonymous$$aybe try a fresh copy? Parents should have no initial effect on the position at all. But, makes the most sense not to make it a child of the hand. Once you throw it, you can't guide it like a sorceror.
I read an article on optimizing in Unity at about 4am. It stated to avoid using instantiation in IOS projects as it's quite expensive and can cause a 'hiccup'. $$anonymous$$aybe this is my hiccup, positioning! This article suggested that you use Spawn$$anonymous$$anager ins$$anonymous$$d. I don't think spawning is appropriate here. Of course I could be wrong. I'll look at instantiating on a simpler and lesser basis!
The "hicup" is the same as if you decided to perform 200 rayCasts in one frame. You'd see a tiny stutter as the frame rate momentarily fell. Won't affect anything besides that.
Getting rid of Instantiate is tricky if you don't already know how: create an array of three balls, offscreen and diabled somehow. Ins$$anonymous$$d of spawning, teleport the ball to where you were going to spawn it, wake it back up, and reset all the vars it uses. If you don't have a problem with frame-rate, don't bother.
@Owen Reynolds Thanks again for responding and hacking this issue out with me. Honestly I don't want to ditch it and try another setup. Its so close to working correctly and looks great. Location, location, position!!!! The app is simple and small enough that no major frame issues arise because of the instantiation. I'll maybe work on a different aspect of the game and come back to the instantiate part in a couple of days.
Your answer
Follow this Question
Related Questions
iOS Instantiate transform as child -- positioning bug 2 Answers
Trying to get a shoot function working in unity using instantiate and it isn't working. 1 Answer
Problem with GetComponentinChildren and Instantiate 0 Answers
how to spawn on random postion but non on static positions 0 Answers
How to follow multiple clones positions of an instantiate prefab having a velocity ? 1 Answer