我创建了一个像Infinite Runner这样的游戏,它在Unity 5的Game选项卡中正常运行,但在Android设备上,当我执行Jump时,它从来没有相同的高度.
[与JhohnPoison回复更新]
注意:在Android 4.4.2和5.0上测试应用程序
注意2:在检查器中添加了一些值.
跳转的功能
void FixedUpdate () {
CheckPlayerInGround();
MakeJump();
animator.SetBool("jump", !steppingDown);
}
void CheckPlayerInGround(){
steppingDown = Physics2D.OverlapCircle(GroundCheck.position, 0.2f, whatIsGround);
}
void MakeJump(){
if(Input.touchCount > 0){
if((Input.GetTouch(0).position.x < Screen.width / 2) && steppingDown){
if(slide == true){
UpdateColliderScenarioPosition(0.37f);
slide = false;
}
audio.PlayOneShot(audioJump);
audio.volume = 0.75f;
playerRigidbody2D.AddForce(new Vector2(0, jumpPower * Time.fixedDeltaTime));
}
}
}
Run Code Online (Sandbox Code Playgroud) 我有一个BonusController脚本作为BonusgameObject的一个组件.这个奖金必须在碰撞时销毁,但必须"行动"几秒钟.我为此启动了一个协同程序,但脚本停止执行(我认为这是因为我将gameObject设置为非活动状态).这是代码BonusController:
void OnTriggerEnter2D(Collider2D col)
{
StartCoroutine(speedUp(1));
gameObject.SetActive(false);
}
IEnumerator speedUp(float seconds)
{
Debug.Log("before");
yield return new WaitForSeconds(seconds);
Debug.Log("after"); // <--- This is never called
}
Run Code Online (Sandbox Code Playgroud)
如何删除对象并且不停止协程脚本执行?
我有阴影和照明问题。
在场景视图中,这是我放大接近关卡布局时看到的:
但是当我在游戏视图中时,我看到的是:
这些是我的相机设置:
如何增加我的阴影视图,以便相机可以看到阴影而不会太接近水平?我的目标是自上而下的游戏,我不希望相机如此放大或接近水平。我在我的设置中遗漏了什么吗?
我正在制作一个spawner脚本,但有一个问题,我无法找到解决方案......
我得到一个错误说
"无法将类型'UnityEngine.Vector3'隐式转换为'UnityEngine.Transform'"
我可以通过添加.position来删除错误,spawningpos但这不起作用,因为它不是对象的转换只是脚本中的转换变量
public GameObject[] spawningObj;
public GameObject[] insects;
public GameObject[] invierment;
public GameObject[] inviermentSingel;
public Transform player;
public int maxNPCsPerChunk;
public int maxInectsPerChunk;
public int maxInviermentalsPerChunk;
public int spawningAria;
private Transform spawningpos;
// Use this for initialization
void Start()
{
if (player == null)
player = GameObject.FindWithTag("Player").transform;
int max = Random.Range(0, maxInectsPerChunk);
for (int i = 0; i < max; i++)
{
spawningpos = new Vector3(Random.Range(-spawningAria, spawningAria) + transform.position.x, 2f, Random.Range(-spawningAria, spawningAria) + transform.position.z);
//Error on …Run Code Online (Sandbox Code Playgroud) 我有一个基类:
public class Base {
public string Foo { get; set; }
public float Bar { get; set; }
public float Foobar { get; set; }
public Base (string foo, float bar, float foobar) {
Foo = foo;
Bar = bar;
Foobar = foobar;
}
}
Run Code Online (Sandbox Code Playgroud)
当我尝试添加扩展此类的类时,我收到错误:
public class Derived : Base {
public Base derived = new Derived ("Foo", 0f, 0f);
}
Run Code Online (Sandbox Code Playgroud)
收到的错误说明如下: Base does not contain a constructor that takes 0 arguments
我在Derived类的第1行得到了这个错误.任何修复/原因导致这种情况发生?
我在Unity中开发的游戏中没有验证GPGS的问题.
屏幕截图: 在imgur.com上查看帖子
发生次数如下:
1.连接到游戏
2. GOOGLE PLAY GAMES窗口弹出并消失(图像上方)
3.出现加载圈然后消失
我在手机上运行了adb logcat,下面是该区域的片段,我认为是问题所在:
04-30 09:45:10.023 11290 11316 W Unity :
04-30 09:45:10.023 11290 11316 W Unity : (Filename: ./artifacts/generated/common/runtime/DebugBindings.gen.cpp Line: 51)
04-30 09:45:10.023 11290 11316 W Unity :
04-30 09:45:10.044 3470 28977 W GamesServiceBroker: Client connected with SDK 8487000, Services 10298448, and Games 39080048
04-30 09:45:10.058 3470 28977 W GamesServiceBroker: Client connected with SDK 8487000, Services 10298448, and Games 39080048
04-30 09:45:10.065 3470 28976 W GamesServiceBroker: Client connected with SDK 8487000, …Run Code Online (Sandbox Code Playgroud) 我的游戏场景中有一个球(球体)和一个地板。Ball.cs附着在球上以控制其在游戏中的移动(球仅在垂直方向移动)。Ball 和 floor 都附有对撞机,每当球接触地板时,理想情况下游戏应该结束。
Ball.cs脚本中的OnCollisionEnter2D方法。
private void OnCollisionEnter2D(Collision2D collision)
{
// Zero out the ball's velocity
rb2d.velocity = Vector2.zero;
// If the ball collides with something set it to dead...
isDead = true;
//...and tell the game control about it.
GameController.instance.PlayerDied();
}
Run Code Online (Sandbox Code Playgroud)
更新功能
void Update () {
//Don't allow control if the bird has died.
if (isDead == false)
{
//Look for input to trigger a "flap".
if (Input.GetMouseButtonDown(0))
{
//...zero out the birds …Run Code Online (Sandbox Code Playgroud) using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Move : MonoBehaviour {
enum MoveProperties
{
DirectionStart,
DirectionEnd
};
public float spinSpeed = 2.0f;
private bool rotate = false;
private bool exited = false;
private List<GameObject> prefabs;
private void Start()
{
InstantiateObjects gos = GetComponent<InstantiateObjects>();
prefabs = new List<GameObject>();
prefabs = gos.PrefabsList();
}
void OnTriggerEnter(Collider other)
{
if (other.gameObject.tag == "Player")
{
Debug.Log("Player entered the hole");
rotate = true;
}
}
private void OnTriggerExit(Collider other)
{
if (other.gameObject.tag == "Player")
{ …Run Code Online (Sandbox Code Playgroud) 我正在搅拌机中创建一个模型:
我想旋转/旋转螺旋桨并控制旋转的时间和速度.我想在unity3d中使用这个模型/对象来进行游戏.
所以我想知道我是否应该首先在搅拌机中制作整个旋转动画部分或者在unity3d中进行?这种螺旋桨是无人机更大型号的一部分.
我是团结3D的新手,我想做一个非常简单的障碍课程游戏.我不希望它有多个级别,但只有一个场景会在每次有人开始游戏时随机生成.
这是一张更好地解释这个想法的图片:
在每个突出显示的部分中,每次应用程序启动时都会生成一个墙,并且玩家只能通过一个间隙,该间隙将在每个部分的任何区域a,b或c中随机生成.我试着查看这个,但这个例子并不多.
如有任何疑问,请不要犹豫.我总是收到回应通知.
谢谢你的时间!
这是一个愚蠢的问题,但我无法弄清楚,我尝试查看它,但没有什么是我想要的,所以我认为询问可能是一个好方法。在我的游戏中,我希望客户端能够向房间中的每个人发送消息(不是为用户发送的消息,如果不是为其他客户端解释为代码):
“(用户1):每个人有多少分?”
“(用户 2):嘿,我得了 5 分”
“(用户 3):嘿,我得了 10 分”
“(用户1):时间到了,说说你的观点:”
“(用户 2):嘿,我得了 20 分”
“(用户 3):嘿,我得了 30 分”
“(用户 1):用户 3 赢了”
当然,这更像是一个图形示例,我想要的是能够向所有客户端(在房间内)发送消息,以便其他客户端可以处理 tjem。我想知道怎么做,以及这是否是一个可能的低谷 PUN(Unity Photon Network)。或者,如果有其他方法可以通过 UnityNetworking 执行此操作。此外,这将通过 LAN 而不是通过 Internet。
先谢谢了。
我正在尝试编写一个脚本,在1.5分钟后将所有灯关闭10秒,然后重新打开.
现在,似乎计时器被绕过了.我意识到这可能是因为时间永远不会是90左右.
话虽如此,我不知道如何得到我想要的结果.
我想过InvokeRepeating改用(如注释掉的那样),但那意味着灯光每次都会关闭更长时间.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class LightsTimerTrigger : MonoBehaviour {
private GameObject[] allLights;
private float time = 0.0f;
private float secondTimer = 0.0f;
void Start () {
// Create array of lights
allLights = GameObject.FindGameObjectsWithTag("riddleLights");
//InvokeRepeating("lightsOn", 60.0f, 120.0f);
//InvokeRepeating("lightsOff", 60.10f, 120.10f); // Exponential
}
// Update is called once per frame
void Update () {
time += Time.deltaTime;
if(time%90 == 0)
{
secondTimer = time;
lightsOff();
Debug.Log("Lights off");
}
if (time == …Run Code Online (Sandbox Code Playgroud) 嗨我在c#中进行了新的编码,我正在编写一个脚本来启用/禁用Unity 5游戏对象点击另一个对象进行这两个动作,第一部分运行正常,但在第二部分重新启用对象时显示此错误:
Assets/Script/Activar.cs(11,5):错误CS1519:类,结构或接口成员声明中的意外符号"else"
这是脚本:
using System.Collections;
using UnityEngine;
public class Activar : MonoBehaviour {
public GameObject modify;
void Update () {
if (Input.GetMouseButton (0))
modify.SetActive (false);
}
else {
modify.SetActive (true);
}
}
Run Code Online (Sandbox Code Playgroud)
那么我该怎么做才能解决这个问题呢?谢谢 :)
unity5 ×13
c# ×10
android ×1
blender ×1
coroutine ×1
gameobject ×1
if-statement ×1
networking ×1
photon ×1
timer ×1