小编Sam*_*tty的帖子

void Start()未被调用

我正在使用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)

c# unity-game-engine

7
推荐指数
1
解决办法
6876
查看次数

如何停止默认动画?

我在Unity 2D(4.3)中制作游戏,每当我开始游戏时,都会播放默认动画.我怎么能阻止这个?我没有告诉它开始void Start()或任何事情......

此外,animation.Play("Anim")不起作用.

我将向您展示我的编辑器的截图:Animator 编辑中的动画师

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

动画师对象

c# animation android unity-game-engine

4
推荐指数
1
解决办法
5544
查看次数

Android Layout Inflater not working?

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)

java xml android-layout layout-inflater

2
推荐指数
1
解决办法
6855
查看次数

(Unity 2D)当它离开屏幕时销毁实例化的预制件?

林做一个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",所以我知道破坏它们的代码有问题.

谢谢

c# android unity-game-engine destroy

1
推荐指数
1
解决办法
1万
查看次数