【发布时间】:2016-05-07 19:06:20
【问题描述】:
我有 5 个预制件作为玩家选项,我的游戏菜单上有一个“更改”按钮,用户可以在其中单击,更改角色。
如何在game2d启动时应用的“菜单”中做出这个选择?
预制件:
Bee、Bee1、Bee2、Bee3 和 Bee4。
蜜蜂(玩家)脚本。
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
using UnityStandardAssets.CrossPlatformInput;
public class Bee : MonoBehaviour {
public float moveSpeed;
public Transform bee;
private Animator animator;
public bool isGrounded = true;
public float force;
public float jumpTime = 0.1f;
public float jumpDelay = 0.1f;
public bool jumped = false;
public Transform ground;
// Use this for initialization
void Start ()
{
animator = bee.GetComponent<Animator> ();
}
void Update ()
{
Move ();
}
void Move ()
{
isGrounded = Physics2D.Linecast (this.transform.position, ground.position, 1 << LayerMask.NameToLayer ("Floor"));
animator.SetFloat ("runB", Mathf.Abs (CrossPlatformInputManager.GetAxis ("Horizontal")));
if (CrossPlatformInputManager.GetAxisRaw ("Horizontal") > 0) {
transform.Translate (Vector2.right * moveSpeed * Time.deltaTime);
transform.eulerAngles = new Vector2 (0, 0);
}
if (CrossPlatformInputManager.GetAxisRaw ("Horizontal") < 0) {
transform.Translate (Vector2.right * moveSpeed * Time.deltaTime);
transform.eulerAngles = new Vector2 (0, 180);
}
if (CrossPlatformInputManager.GetButtonDown ("Vertical") && isGrounded && !jumped) {
// rigidbody2D.AddForce (transform.up * force);
GetComponent<Rigidbody2D> ().AddForce (transform.up * force);
jumpTime = jumpDelay;
animator.SetTrigger ("jumpB");
jumped = true;
}
jumpTime -= Time.deltaTime;
if (jumpTime <= 0 && isGrounded && jumped) {
animator.SetTrigger ("groundB");
jumped = false;
}
}
}
【问题讨论】:
-
预制件有什么区别?例如。如果它只是在视觉效果上有所不同,您应该使用一个预制件并让它的某个子级保持视觉效果(例如精灵)并且只改变它。
-
@Gunnar B. 只改变精灵,其他都一样!
标签: c# unity3d unityscript unity5 unity3d-2dtools