- Home /
Passing position to function
I'm passing the position of the collider to the PlatformerController script to perform some calculations on it, but get an error saying I can't perform operations on an 'Object' with a 'Vector3'. What do I need to do to make the passed transform.position into a Vector3?
function OnTriggerEnter(hit : Collider) {
if (hit.transform.name == "Grabber") {
var platformerController : PlatformerController = hit.transform.parent.GetComponent(PlatformerController);
// Send ledge position
platformerController.GrabMe(transform.position);
}
}
function GrabMe (ledgePosition) {
var ledgeOffset = Vector3(0, 0, 0);
transform.position = ledgePosition - ledgeOffset;
}
Answer by DaveA · Mar 19, 2012 at 09:04 PM
function GrabMe (ledgePosition : Vector3)
BTW Vector3(0,0,0) same as Vector3.zero
Ahh… because it's declaring a variable in the parenthesis. $$anonymous$$akes sense, thanks Dave!
And yeah, I know about Vector3.zero, was just doing a quick example. :)
Your answer
Follow this Question
Related Questions
How to get Raycast to detect collision with Object? 3 Answers
Remaping values? 1 Answer
Changing character colour on code 1 Answer
How to assign an object to variable C#? 1 Answer
How could I convert the y axis in a Vector 3 into a float? 1 Answer