I need help desperately…what i wanted 2 do is basically…when I click(using left mouse button) on my gameobject my animation will play…
-my animation is from C4d, it have been baked and imported it 2 unity
I need help desperately…what i wanted 2 do is basically…when I click(using left mouse button) on my gameobject my animation will play…
-my animation is from C4d, it have been baked and imported it 2 unity
First off, welcome to the forums! ![]()
When posting questions like this it really helps to:
Provide the code you’re using, there are lots of ways to write code that won’t work, without seeing yours it’s hard to help.
Provide a more complete description on exactly what is not working for you or where you are stuck. Should we help with basic mouse click detection? Are you getting the click yet unable to play the animation? Both? Something else?
So, can you provide a snippet of code if you have some? Can you also share with us what’s working, or not working, or where you need help with all this? Providing that sort of information will help us help you, and we’re here to do that! ![]()
TKs for the reply…so basically tis wat im hoping to go for =
function OnMouseDown () {
if(gameObject.name == “sewing machine”)
animation.Play(“sewing”);
}
when i click on my game object there is no animation…and im not reli sure whether the object detects my mouse clicks…haha…help meeeeee :o im reli a noob on tis program…
Put a box collider on the sewing machine and put this code on a script on the machine:
var playing : boolean = false;
function OnMouseDown()
{
if (!playing) {
playing = true;
animation.Play("sewing");
yield WaitForSeconds(animation["sewing"].length);
playing = false;
}
}
heyx2…tks for d quick reply Sunman…reali appreciate it… ![]()
The code u gave me didnt seem to work…ive put the box collider and the script on my sewing machine btw…
Check to make sure that the box collider covers the object, that the script is on the same piece of the object if it has multiple pieces, and try adding a rigidbody.
If it still doesn’t work, just share the project file and I’ll see what’s up.
Hello everybody
just started with unity beeing a toatal dump newbie in
scripting but this code worked for me thanks
‘:)’
here is my Situation:
i have got an imported cinema4d file containing a cube
beeing animated from A to B and back to A using 3 keys.
I want to use left mouse clicks to move that cube back and forth.
here is how far i got and some speculations raised from reading the manual.
thanks for help in advance
// box_move_a2b_b2a script:
// with that script i want to move that cube/box from a to b where it should stay after the first
// onMouseDown event of a user and rest there until a second click. After the cube/box arrived in postion b
// it should be able to play the seccond animation provided in the timeline of the imported cinema 4d file
// from frame 20 untill frame 40 which moves the cube/box back into the original position a.
// In unity i called this animation box_back in the Split animations menue of the imported file.
// After draging the imported file(its called box ani) into scene hierarchy
// with the file still beeing selected in the hierarchy window i applied the animation
// called box_back in the right inspector menue in the Animations section found under the the small down pointing
// black rectangle ( grrr… that took me ages i must be toatally dump).
// After hitting play this results in the box beeing moved from postion a to b corectly after i clicked on it
// if clicked again it repeats that move–
fine but now i want to have it move back to its original position when clickin the second time.
:idea:
My guess is that i have to use the comand animation.state or Animation.AddClip
or is it a timing issue,
or is it that i have use 4 keys in advance to
seperate the animations
???
:?
used code in script:
function OnMouseDown () {
var playing : boolean = false;
if (!playing) {playing = true;
animation.Play(“box”);
yield WaitForSeconds(animation[“box”].length);
playing = false; }
}