小编Ran*_*ngo的帖子

从Unity中的脚本获取对按钮的引用

该脚本附加到不在场景中的预制件.按钮有标签.

我试着在检查器中拖放按钮,但引擎不会让我.我尝试通过标签找到它,但我得到一个异常"不能隐式转换类型UnityEngine.GameObject到UnityEngine.UI.Button",当我转换时,我得到一个异常,我无法通过内置转换转换这些类型.一些帮助?如何获得对按钮的引用?这是代码:

using UnityEngine;
using System.Collections;
using UnityEngine.UI;

public class TankShooting : MonoBehaviour {

    private Transform ShootingCameraTransform;
    private PlayerTankMovement playerTankMovement;
    public Button shootButton;


    // Use this for initialization
    void Start () {

        shootButton = GameObject.FindGameObjectWithTag ("ShootButton") as Button;
        shootButton.onClick.AddListener ((UnityEngine.Events.UnityAction)this.OnShootButtonClick);

        playerTankMovement = GetComponent<PlayerTankMovement> ();
        Transform t = transform;
        foreach (Transform tr in t)
        {
            if (tr.tag == "ShootingCamera") 
            {
                ShootingCameraTransform = tr.transform;
            }
        }
    }

    // Update is called once per frame
    void Update () {

    }

    public void OnShootButtonClick() …
Run Code Online (Sandbox Code Playgroud)

c# user-interface button unity-game-engine

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

旋转对象以面向相反方向

我有一个对象 A 和 B。当我点击对象 B 时,A 旋转到对象 B(A 面对 B)。B不面对A。我需要做的是:当A面对B时,我需要A面对相反的方向。我有 A 旋转看 B 的代码。之后如何旋转到相反的方向?

Vector3 targetDirection = target - transform.position;
float step = speed * Time.deltaTime;
Vector3 newDirection = Vector3.RotateTowards (turretDome.transform.forward, targetDirection, step, 0.0F);
turretDome.transform.rotation = Quaternion.LookRotation (newDirection);
Run Code Online (Sandbox Code Playgroud)

vector rotation direction unity-game-engine

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

如何在README.md中水平堆叠图像

我想在 github 上的 README.md 文件中水平堆叠图像。

<img src = "screenshots/tool.png" width ="200" />

<img src = "screenshots/world_flash.png" width ="200" />
Run Code Online (Sandbox Code Playgroud)

这会产生这样的效果:在此输入图像描述

我希望他们成为一个挨着一个的人。怎么做?

html markdown image github

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