标签: unityscript

使用Unity开发的最佳语言?

我想问你关于Unity框架和编程的所有内容.Unity支持三种不同的语言; Boo,C#和Unityscript.假设您不熟悉OS X上的编程和开发.

Unity和Unity一起学习和使用的最佳语言是什么?

c# boo unity-game-engine unityscript

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

如何在统一中等待特定的秒数

我想通过每1秒实例化7个立方体来制作统一2d游戏中的加载条.我使用: yield WaitForSeconds(1); 在每个实例化语句后的函数更新中,但它不起作用:((我得到一个错误:

脚本错误:Update()不能是协程.

还有其他想法吗?

我创建了一个新的场景并将其命名为"lost"然后我编写了这个脚本并将其附加到主摄像头:

#pragma strict

//var loadingBar: Transform;
var loading_bar : GameObject;

function Update()
{
    Instantiate(loadingBar,Vector3(-1.849,-2.9371,2),Quaternion.identity);

    gameTimer();


    Instantiate(loadingBar,Vector3(-1.2909,-2.937,2),Quaternion.identity);

    gameTimer();

    Instantiate(loadingBar,Vector3(-0.5566,-2.93711,2),Quaternion.identity);

    gameTimer();

    Instantiate(loadingBar,Vector3(0.148236,-2.93711,2),Quaternion.identity);

    gameTimer();

    Instantiate(loadingBar,Vector3(0.823772,-2.93711,2),Quaternion.identity);

    gameTimer();

    Instantiate(loadingBar,Vector3(1.440567,-2.93711,2),Quaternion.identity);

    gameTimer();

    Instantiate(loadingBar,Vector3(2.057361,-2.93711,2),Quaternion.identity);

    loadingTimer();

    Application.LoadLevel(1);
}


function OnGUI()
{
    GUI.color = Color.green;
    GUI.Label(Rect(400,350,500,500),"<color=green><size=100>Lose</size></color>");
}

function loadingTimer()
{
    yield WaitForSeconds(1);
}
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

我希望这些立方体能够在1秒后相互显示,所以它看起来像一个加载栏......

我这样解决了这个问题::

#pragma strict

var loadingBar: Transform;
var finished : boolean = false;

function Update()
{
    loadingTimer();

    if (finished == true)
    {
        Application.LoadLevel(1);
        finished= false;
    }
}


function OnGUI()
{
    GUI.color …
Run Code Online (Sandbox Code Playgroud)

unity-game-engine unityscript

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

将播放器信息保存在外部文件中

这是我在团结世界中第一次测试2d游戏中的主菜单:

在此输入图像描述

我想保存高分,如果玩家按下"最佳分数"按钮我想给他们显示最好的分数^^,所以我想我需要使用外部文件来保存这类信息并在运行时打开它时间......怎么样?哪种文件最适合执行?

unity-game-engine unityscript

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

在Unity中闪烁游戏对象

如何使用SetActiveRecursively(Moment = 1秒)在Unity中创建闪烁对象.

我的例子(改变):

public GameObject flashing_Label;

private float timer;

void Update() {

while(true)
{
flashing_Label.SetActiveRecursively(true);
timer = Time.deltaTime;

  if(timer > 1)       
          {
            flashing_Label.SetActiveRecursively(false);
            timer = 0;        
          }   
 }

}
Run Code Online (Sandbox Code Playgroud)

c# unity-game-engine ngui unityscript

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

为什么数组是空的

我刚刚开始学习Unity3D javascript,这是我第一次尝试学习,试图复制一个洗牌的Objective-C代码片段,我有以下代码:

function Shuffle(theCardArray : Array) {
var dupeArray = new Array();
var count = theCardArray.length;

print("theCardArray: " + theCardArray);


dupeArray = theCardArray;
    count = dupeArray.length;
print("A) Count dupeArray: " + count);
print("B) Count dupeArray: " + dupeArray.length);
theCardArray.Clear();

for (var i = 0; i < count; i++) {

    // Select random element between i and the end of the array to swap it
    var nElements = count - i;
    var n = Random.Range(0, nElements);

    print("#1");
    print("C) Count dupeArray: " …
Run Code Online (Sandbox Code Playgroud)

javascript unityscript

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

团结的承诺

我想要一个Character类,继承MonoBehavior并暴露一些方法:Walk,Attack,......

但是,假设两个组件同时使用这些方法,我想将操作排队并有一些方法来通知组件他们的操作已被执行.

在Javascript标准中,我会做这样的事情:

var Character = function ( ) {
    this._deferred = new Deferred( );
};

Character.prototype.walk = function ( ) {
    return this._deferred = this._deferred.then( function ( ) {
        // Do the actual walk
    } );
};

Character.prototype.attack = function ( ) {
    return this._deferred = this._deferred.then( function ( ) {
        // Do the actual attack
    } );
};

var character = new Character( );

// Component A
character.walk( ).then( function ( ) {
    // Executes when the walk …
Run Code Online (Sandbox Code Playgroud)

c# unity-game-engine unityscript

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

从鼠标点击位置转换

尝试了这百万种方式,总是得到转换错误.我只是在一个平面上点击,希望点击鼠标位置以进入变换变量,以便我的角色走向那一点.我var target: Transform;用来定义角色移动的位置.如何从世界空间中的点击中提取该类型的变量,该点击将与平面(或任何东西)相交?

var WalkingSpeed = .05;

// The target marker.
var target: Transform;

// Speed in units per sec.
var speed: float;

static var mousePos : Vector3;

function Update() {
    // get distance between objects current position and the target position
    var distance = Vector3.Distance (target.transform.position, transform.position);

    if(distance > 0) {
        // we are still not at the target, do walking animation
        animation["walk"].speed = 1;    // set speed of animation
        animation.CrossFade("walk");    // actually play the animation
    } …
Run Code Online (Sandbox Code Playgroud)

unity-game-engine mouseclick-event unityscript

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

Unity3d进度条

我正在使用unity3D开发游戏,我需要帮助制作进度时间栏,以便在收集特定项目时添加时间,从而继续游戏.

c# unity-game-engine unityscript unity3d-gui

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

在Unity 3D/spheres中翻转法线

我已经为我的游戏编写了这个代码,我想要的是在一个纹理上翻转法线.我有一个模型和一个纹理,并希望纹理在球体模型内而不是在外面.我想通过在翻转纹理顶部的球体内部的图像周围移动相机来创建360度全景效果.

现在,当我第一次按下播放按钮时,它工作得很好,但是当我停下来并想再次播放时,我看不到电路板,也看不到周围环境.

它似乎每2次尝试一次.我对此很陌生,我不知道我的错误在哪里.

using UnityEngine;
using System.Collections;

public class InvertObjectNormals : MonoBehaviour 
{
    public GameObject SferaPanoramica;

    void Awake()
    {
        InvertSphere();
    }

    void InvertSphere()
    {
        Vector3[] normals = SferaPanoramica.GetComponent<MeshFilter>().sharedMesh.normals;
        for(int i = 0; i < normals.Length; i++)
        {
            normals[i] = -normals[i];
        }
        SferaPanoramica.GetComponent<MeshFilter>().sharedMesh.normals = normals;

        int[] triangles = SferaPanoramica.GetComponent<MeshFilter>().sharedMesh.triangles;
        for (int i = 0; i < triangles.Length; i+=3)
        {
            int t = triangles[i];
            triangles[i] = triangles[i + 2];
            triangles[i + 2] = t;
        }           

        SferaPanoramica.GetComponent<MeshFilter>().sharedMesh.triangles= triangles;
    }
}
Run Code Online (Sandbox Code Playgroud)

unity-game-engine unityscript

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

Unity3d创建具有预定结果的骰子

我有一个预制件(骰子).由于我的游戏是多人游戏,因此我会在玩家实际滚动之前生成掷骰子的结果.然后我将该值发送给游戏.我想取这个值并创建一个模具滚动,结果是预定值.最好的方法是什么?我想这是一个动画(每个结果1)但我不知道从哪里开始.我已经找到了关于创建骰子动画的教程但却找不到任何东西.或者,这可以在代码中完成吗?如果是这样,方向上的任何指针都会很棒.

谢谢

c# unity-game-engine unityscript unity5

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