- Home /
'center' is not a member of 'Object'
i'm getting these:
BCE0019: 'center' is not a member of 'Object'.
BCE0019: 'size' is not a member of 'Object'.
errors, when i try use this code to change the box collider size of my object
function Start(){
boxColl=this.GetComponent(BoxCollider2D);
}
from what i found online this is how you obtain the boxcollider2d from the object (i tried this.BoxCollider2D.size and just BoxCollider2D.size)
function keyMovements(){
if (Input.GetButton("Down")){
boxColl.center=Vector2(1.31,2.4);
boxColl.size=Vector2(0,0);
}else{
boxColl.center=Vector2(1.31,2.4);
boxColl.size=Vector2(0,0);
}
any hints as to what i am doing wrong? i'm missing many fundamental things with unity and its causing the speed of my programming to lessen the more advanced i get with my scripts. (so use small words ;) )
where have you defined boxColl, and what type have you defined it as?
also, hopefully your code is just an example because you're setting the center & size to the same thing in both conditions.
i haven't, although i should. it's defined as
var boxColl;
this is basically my failed attempt at creating a solution to the problem by manipulating other boxcollider questions and the documentation.
and yeah i haven't changed the x and y because i found those errors before i ended up writing them in (i copied and pasted and was just about to check what the new box collider would look like in the editor)
what happens if you change it to the following?
var boxColl : BoxCollider2D;
Umm.. okay... i've written it just like that about 2 times and i swear i made sure that it was correctly written but it gave me lots of errors... Thanks :)
(seriously whenever i ask a question on here its the dumbest thing i've forgotten and just couldn't find)
so, did it work?
and don't worry about asking questions - it's all part of learning...
Your answer
Follow this Question
Related Questions
RayCasts and BoxCollider2D not working? 2 Answers
How to make BoxColidier to have transparent side? 1 Answer
How can i detect which side of a box collider 2D the collider object collided with? 2 Answers
Boxcollider2D, Trigger not working 2 Answers
Problem with 2D collision detection (Wide object falls through a thin hole) 1 Answer