- Home /
The question is answered, right answer was accepted
How to solve this component error prolbem?
i am using this coding for the bouncing my player . var BounceAmount : float; //How high should we bounce?
function OnTriggerEnter(other : Collider){ //Bouncy trigger
if(other.tag == "Player"){ //Is this the player?
var P = GameObject.FindGameObjectWithTag("Player"); //Grab the palyer object
//Access CharacterMotor Script
//Set vertical speed of movement to bounce amount.
P.GetComponent("CharacterMotor").movement.velocity.y = BounceAmount;
}
}
error details: /Bouncybox.js(9,42): BCE0019: 'movement' is not a member of 'UnityEngine.Component'.
@hacked - please don't post your question as an 'Answer' to a completely unrelated question.
Answer by Linus · Feb 20, 2014 at 03:03 PM
You do not need to find the object. You get that from the collider.
See http://docs.unity3d.com/Documentation/ScriptReference/Collider.html for details on what you can get from the collider.
Please use the 1010101 button to make your posted code more readable.
Let me know if you prefer a solution that used FindGameObjectWithTag.
For this to work the player object must have a component called CharacterMotor
var BounceAmount : float; //How high should we bounce?
function OnTriggerEnter(other : Collider){
//Bouncy trigger
if(other.tag == "Player"){
//Is this the player?
var CM : CharacterMotor = other.transform.GetComponent("CharacterMotor");
CM.movement.velocity.y = BounceAmount;
}
}
Follow this Question
Related Questions
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
When do we need to use Class? 1 Answer
how to create Magnetic repulsion ? 0 Answers
hide object start script 4 Answers