- Home /
Please someone help with this please been trying to get this working for 4 days
The problem is i have 2 game object 1. is my character 2. is The Mad Doc that has the animations attached to it.
now the problem is i have a script attached to the character called "Die Script" and i want to write some code in there that will initialize an animation from the mad doc animation script. I will show you both of the codes (If any one requires more info please let me know on here or skype:johnesslemont012)
Die Script
private var dead = false; private var dying = false;
var mydeadsound : AudioClip;
function OnControllerColliderHit(hit : ControllerColliderHit) {
//if hit fallout and player is not already dead if((hit.gameObject.tag == "fallout")&&(!dying)) { dying=true; HealthControl.LIVES -=1;
AudioSource.PlayClipAtPoint(mydeadsound,transform.position); yield WaitForSeconds(2.7);
dead = true;
}
}
function LateUpdate() { if(dead)
{
transform.position = Vector3(69.05988,0.8250099,0.01707077);
dead = false; dying = false;
}
}
and here is the mad doc animation script which is called "Walk"
function Awake() { animation["Idle"].layer = 0; animation["Run"].layer = 1; animation["Jump"].layer = 2; animation["Dead"].layer = 3; }
function Update() { if (Input.GetKey("d")) { animation["Run"].wrapMode = WrapMode.Loop; animation.Play("Run");
} else{ if (Input.GetKeyUp("d")) animation.Stop(); animation["Idle"].wrapMode = WrapMode.Loop; }
if (Input.GetKey("a")){ animation["Run"].wrapMode = WrapMode.Loop; animation.Play ("Run"); } else{ if (Input.GetKeyUp("a")) animation.Stop(); animation.CrossFade ("Idle");
}
if (Input.GetKey("right")) { animation["Run"].wrapMode = WrapMode.Loop; animation.Play("Run");
} else{ if (Input.GetKeyUp("right")) animation.Stop(); animation["Idle"].wrapMode = WrapMode.Loop; }
if (Input.GetKey("left")){ animation["Run"].wrapMode = WrapMode.Loop; animation.Play ("Run"); } else{ if (Input.GetKeyUp("left")) animation.Stop(); animation.CrossFade ("Idle");
}
if (Input.GetButtonDown("Jump")) { animation.CrossFade("Jump"); } else{ animation.CrossFade("Idle"); }
}
Can you edit your post so the code is formatted correctly. Highlight all of your code. Click the code button twice.
Clicking the code button once is sufficient...clicking twice undoes the formatting.
Answer by Ferazel · May 12, 2011 at 03:29 PM
The easiest way would be to make a variable in the die script that links it directly to the MadDoc script. So in your Die Script put a variable:
public MadDocScript scriptObj;
Then in the editor you should see a variable on your DieScript that you can drag and drop the MadDoc component onto. Then within the DieScript you may access any public members/methods on the MadDoc script via the scriptObj variable. So in your DieScript it could be something like:
void Update() {
if(Input.GetKey("d")) {
scriptObj.InitializeAnimation();
}
}
or something similar to that.
How ouwld i write that in java as i am a complete noob at c#
Java =/= Javascript. Please don't confuse them. Use JS as shorthand for Javascript if you must.
Also, learn to convert JS and C#, there really are just a few things you generally have to do. Fix variable declarations and whatnot. Clicking back and forth between JS and C# in the Unity reference will show you differences.
Your answer