- Home /
card rotation ::click & jump+rotate
hi folks!
don't know if i am too stupid or unity is full of bugs. it couldn't be that hard to generate a playcard which jumps up and rotates 180 (lets call this "flip") when clicked...
please show me your shortest scripts of a flipCard-class! still learning...
thnx!
o.k. - not that short, please. it should make the card flip and jump smoothly...
Answer by Eric5h5 · Apr 23, 2010 at 07:09 PM
Probably best to use existing animation functions instead of reinventing the wheel. There's AniMate, Tween, and iTween for fancy stuff, and MoveObject for something basic. Using MoveObject, you can do
var moveTime = .5;
function OnMouseDown () { MoveObject.use.Translation(transform, Vector3.up, moveTime, MoveType.Time); MoveObject.use.Rotation(transform, Vector3.forward * 180.0, moveTime); }
to make the card move up one unit and flip 180 degrees along the Z axis smoothly over half a second.
i should go to wiki first when i write code. i always wrote these things myself :) you are the unify king eric!
Yep, Unify is good, I've found lots of useful stuff on there.
hey, this looks good. especially because i come from AS3 and use lots of Tweeners. thanx!
Answer by Ashkan_gc · Apr 23, 2010 at 11:59 AM
if you want to rotate the card instantly it's to simple. attach a collider like box collider to your gameObject of card and create a script in javascript like this.
function OnMouseDown ()
{
transform.Translate (0,1,0); //moves the card 1 meter up in +y direction
transform.Rotate (0,0,180); //rotate 180 degrees around z axis
}
so easy. if you want to do it in several frames so you need to use coroutines. if you need more help or C# code just comment here. unity is the easiest engine that you can use for 3d game development so don't worry
Answer by Felipetnh · Aug 25, 2014 at 06:34 AM
I know this is a very old topic, but I'm having difficulties using Eric's solution in C#. I can get it working fine in JS, but no matter what I do, I can't get it working in C#...
It always says that MoveObject does not exist in the current context.
Your answer
