unity 前进后退脚本

This tutorial will show you how to build an MC that acts like a button that plays an animation on rollover, and plays backwards on rollout. Download the sample files here.

本教程将向您展示如何构建一个MC,该MC的作用类似于一个按钮,该按钮在过渡时播放动画,而在过渡时向后播放。 在此处下载示例文件 。

(Instructions)

1. Start a new Flash project and go to Insert, New Symbol.

1.启动一个新的Flash项目,然后转到“插入”,“新符号”。

2. Give the symbol a name — let’s call it "mc". Click Movie Clip, and then ok.

2.给符号起一个名字-我们称它为“ mc”。 单击影片剪辑,然后单击确定。

3. Now, let’s create the animation.

3.现在,让我们创建动画。

Create whatever animation you want your "mc" to display, whether it’s a shape tween, motion tween, or frame-by-frame animation. Create only the forward animation — there’s no need to create the backward animation.

创建您想要“ mc”显示的任何动画,无论是补间动画,补间动画还是逐帧动画。 仅创建前向动画-无需创建后向动画。

Then click the first frame and press F2 (if you’re using Flash MX, or F9 if you’re using Flash 5). This will bring up the action window. Insert a stop(); command there. Then, place it into the timeline.

然后单击第一帧,然后按F2键(如果使用的是Flash MX,或者按F9键(如果使用的是Flash 5))。 这将打开操作窗口。 插入一个stop(); 命令在那里。 然后,将其放入时间轴。

4. Once you’re done creating the animation, drag the "mc" symbol from the library onto the main timeline, and place it into the frame and layer of your choice.

4.创建完动画后,将“ mc”符号从库中拖到主时间轴上,然后将其放置到您选择的帧和图层中。

5. Now click the "mc" and press F2 in Flash MX (or F9 in Flash 5), to bring up the actions window, and apply the following code. Note that you’ll have to do this every time the mc is placed on the main stage.

5.现在单击“ mc”,然后在Flash MX中按F2(在Flash 5中按F9),以显示“操作”窗口,并应用以下代码。 请注意,每次将mc放置在主舞台上时,都必须执行此操作。

onClipEvent (enterFrame) { // runs a hit test

  if (this.hitTest(_root._xmouse, _root._ymouse, true)) { 

    this.nextFrame(); // if true the mc plays forward 

  } else { 

    this.prevFrame(); // if not plays backwards to beginning 

  } 

}

If you test your movie, you’ll notice that it doesn’t bring up the hand like a button would.

如果测试电影,您会注意到它不会像按钮那样举起手。

6. For a real easy fix, go back and edit your "mc" and insert a top layer.

6.要真正轻松地修复,请返回并编辑“ mc”并插入顶层。

7. Now, create a shape (or other graphic element) in the new layer, which spans the length of your animation’s frames, and covers the animation.

7.现在,在新层中创建一个形状(或其他图形元素),该形状跨越动画帧的长度并覆盖动画。

8. Click the new layer to select the object you just made. Then click, Insert and Convert to Symbol. Call it "hidden" and select button, then Ok. Now your object is a button!

8.单击新层以选择刚创建的对象。 然后单击“插入并转换为符号”。 将其称为“隐藏”并选择按钮,然后单击确定。 现在,您的对象就是一个按钮!

9. Double-click the "hidden" button to bring up its edit window.

9.双击“隐藏”按钮以打开其编辑窗口。

10. Right-click the up state frame, click "cut frame", and paste it into the "hit" frame, making the button invisible.

10.右键单击向上状态框架,单击“剪切框架”,然后将其粘贴到“命中”框架中,以使按钮不可见。

11. Now, to make the "mc" act like a button:

11.现在,使“ mc”像按钮一样起作用:

  • On the main time line, click on a frame that you’d like the play head to go to when the "hidden" button is clicked.
  • Insert a frame label of "here".
  • Now, back inside the "mc" movie clip, click your "hidden" button to bring up the action window, and apply this code:
on (release) {

  _root.gotoAndPlay("here"); // _root. targets the main movie 

}

Note that placing the buttons near the edge of the movie can ruin this effect, as the movie animates backwards by detecting when the mouse leaves the mc.

请注意,将按钮放在影片边缘附近可能会破坏此效果,因为影片会通过检测鼠标何时离开mc来向后动画。

If the user goes off the button edge after animation, and your button is placed too close to the edge of the mc, it won’t be able to detect the mouse leaving the mc area, and won’t play the backwards animation.

如果用户在动画后离开按钮边缘,并且您的按钮放置在离mc边缘太近的位置,则它将无法检测到鼠标离开mc区域,并且将无法播放向后动画。

翻译自: https://www.sitepoint.com/backward-button-effect-2/

unity 前进后退脚本