我正在使用2D模式在Unity 4.3中制作游戏.但由于某种原因,该void Start()功能未在场景开始时调用.我甚至附加了一个Debug.Log("Hello");启动函数,但它甚至没有这样做,所以我知道Start()函数没有被调用.虽然,该Update()函数被调用.
这是脚本.
private void Start()
{
this.animation.Stop();
Debug.Log("Hello");
}
Run Code Online (Sandbox Code Playgroud)
你可以看到,有一个确实有效的Update方法.
编辑:整个脚本:
public class Player : MonoBehaviour
{
public Vector2 jumpForce = new Vector2(0, 300);
public Vector2 moveForce = new Vector2(0, 300);
public Vector2 sideForce = new Vector2 (250, 0);
public GameObject obstacle;
public float scrollSpeed = 30;
public AnimationClip fly;
public GameObject player;
private float speed = 10.0f;
private void Start()
{
Debug.Log("hi!");
this.animation.Stop();
Debug.Log("Hello");
}
private void Update() …Run Code Online (Sandbox Code Playgroud) 我在Unity 2D(4.3)中制作游戏,每当我开始游戏时,都会播放默认动画.我怎么能阻止这个?我没有告诉它开始void Start()或任何事情......
此外,animation.Play("Anim")不起作用.
我将向您展示我的编辑器的截图:Animator

我的播放器上的动画制作者对象

I have an inflater in my main java class, mainly because I want to be able to 'findViewById' in a layout other then the one set in 'setContentView' (activity_main.xml).
Since I'm new to Android dev and Java in general, I thought I could do this with a layout inflater. Anyway, the layout I'm trying to inflate a layout named "box_middle".
This is my code where I create the inflater (and try to use it).
LayoutInflater inflater = (LayoutInflater)this.getSystemService (Context.LAYOUT_INFLATER_SERVICE);
View …Run Code Online (Sandbox Code Playgroud) 林做一个2D游戏在Unity 2D(4.3),我需要销毁时,这些组合屋去关闭屏幕实例化的组合屋.我已经编写了一些代码来生成Objects,但是当我们离开屏幕时我想要删除那些预制件.这是我到目前为止编写的代码.
要生成预制件(C#):
void Update () {
float y = Random.Range(-4.53f, 2.207f);
if(x < 2000) {
Instantiate(obstacle, new Vector3(y, x * 6.0f, 0),Quaternion.identity);
x++;
}
//Debug.Log(x);
}
Run Code Online (Sandbox Code Playgroud)
要销毁预制件(C#):
/*************************************************************************************************
* GET INSTANTIATED OBSTACLE
* AND DESTROY IT ON EXIT
* TO SAVE MEMORY
**************************************************************************************************/
GameObject clone = (GameObject)Instantiate (obstacle);
/*if(clone.transform.position.y == -11)
{
Destroy(clone);
Debug.Log("Destroy");
}*/
Vector2 screenPosition = Camera.main.WorldToScreenPoint(transform.position);
if (screenPosition.y > Screen.height || screenPosition.y < 0)
{
Destroy(gameObject);
Debug.Log("Destroy");
}
Run Code Online (Sandbox Code Playgroud)
但是,销毁对象的代码不起作用,但也没有出现错误.在预制件离开屏幕后输出"Destroy",所以我知道破坏它们的代码有问题.
谢谢