- Home /
stopping animal from growing once it reaches a certain size.
Hi guys, I'm trying stop a creature from getting bigger and I'm not sure how to do it or fix the errors I'm getting. If anyone could help that would be fantastic and much appreciated.
var growth : GameObject;
var Value : float;
var scle;
var CsScript:Detonator;
var size: Transform;
function Awake(){
CsScript = this.GetComponent("Detonator");
size = growth.transform.lossyScale;
}
function Update () {
if(Time.timeScale == 1.0){ //if the game is paused or on the menu the horse won't move
if(size.position.x < 2){ //if the horse is still small enough
scle = Value/1000; //gives me a value i can work with
growth.transform.localScale += Vector3(scle,scle,scle);
//increases the size of the horse
}
else{
Blow(); //explodes if it is too big
}
}
}
function OnGUI(){
if (MainCode.Attrib == true){
Value = GUI.HorizontalScrollbar (Rect (25, 25, 100, 30), Value, 1.0, 0.0, 10.0);
}
}
function Blow(){
CsScript.Explode();
}
The problem I keep getting is as follows: Assets/Growth.js(10,33): BCE0022: Cannot convert 'UnityEngine.Vector3' to 'UnityEngine.Transform'.
Answer by Coderdood · May 22, 2013 at 08:58 PM
The problem is exactly as described in the error message. It is not possible to convert a 'Vector3' to a 'Transform'.
This occurs in the awake function:
function Awake()
{
CsScript = this.GetComponent("Detonator");
size = growth.transform.lossyScale; // This line is an error
}
My guess from reading the code is that you want to actually store the transform. So change the awake function to:
function Awake()
{
CsScript = this.GetComponent("Detonator");
size = growth.transform;
}
That should fix your problem.
Thanx very much. With this I was able to finish my game Assignment on time.
Your answer
Follow this Question
Related Questions
Why isn't my teleport on collision script working? 0 Answers
How do I perform math on Vector3.x or Vector4.x as if it were a float? 3 Answers
Is there a way to scale everything in my game (GUI, text size, etc.) on Android in Javascript? 2 Answers
Still confused on lerps... 1 Answer
Destroy object with more clicks depending on Scale? 0 Answers