- Home /
GetComponent() problems
So I am trying to get the size of my Collider, but it keeps giving me errors.
#pragma strict
static var CldHeadD : int[];
static var CldLeftD : int[];
static var CldRightD : int[];
static var CldFeetD : int[];
static var CldcornersD : int[];
static var Skin : float = 0.9;
static var Size : Vector2;
static var tp : Vector3;
function Start () {
CldHeadD = new int[4];
CldLeftD = new int[4];
CldRightD = new int[4];
CldFeetD = new int[4];
CldcornersD = new int[4];
}
function FixedUpdate () {
tp = transform.position;
Size = this.GetComponent<BoxCollider2D>().size;
for (var XU : int = 0; XU <= CldHeadD.length; XU++){ /*aray length*/
var HitUp = Physics2D.Raycast(Vector2(/*pos.x*/tp.x + (XU - (Size.x * 0.5)) * Skin/*pos.x*/, /*pos.y*/ tp.y + (Size.y * 0.5) * Skin/*pos.y*/), Vector2.up);
CldHeadD[XU] = HitUp.distance;/*Set distance*/
print(CldHeadD);
}
}
and I get these errors.
Assets/Jorge/Scripts/Player/NEW/Colliding2.js(22,49): BCE0043: Unexpected token: ).
Assets/Jorge/Scripts/Player/NEW/Colliding2.js(22,50): BCE0044: expecting ), found '.'.
Assets/Jorge/Scripts/Player/NEW/Colliding2.js(22,51): UCE0001: ';' expected. Insert a semicolon at the end.
Answer by Eric5h5 · Jul 07, 2015 at 08:59 PM
You're trying to use C# syntax for GetComponent.
size = GetComponent(BoxCollider2D).size;
Answer by YoungDeveloper · Jul 07, 2015 at 08:23 PM
this is object - component itself and not gameobject, i believe it should be
Size = this.gameObject.GetComponent<BoxCollider2D>().size;
Nope, but there's no reason to use "this" in the first place.
i agree, i wrote in the same manner for the op and you are right about c# syntax, i guess i shouldn't be giving hints as a c# programmer lol
@YoungDeveloper: No, just learn more UnityScript, even if it's just to collect arguments for why you're not using it ^^. At least that's what i do most the time :D
@Bunny83 I know it quite well, the problem starts when i start to give advices after 14 hours of non stop program$$anonymous$$g haha, i should have seen it
Your answer
Follow this Question
Related Questions
Collision isn't detected between two obects 1 Answer
Create clickable GameObjects (JS) 1 Answer
Launching a Projectile to a Raycast 1 Answer
Need Help Converting 3d Raycast Into a 2D Raycast 2 Answers
2D Jump AI Help 0 Answers