我有一个物体,我试图让玩家输入触发器并按下一个键,交换相机。
我的代码:
public class Canhao : MonoBehaviour
{
public Camera cameraPlayer;
public Camera CameraCanhao;
private void Start()
{
cameraPlayer.gameObject.SetActive(true);
CameraCanhao.gameObject.SetActive(false);
}
private void OnTriggerEnter(Collider other)
{
if(other.gameObject.CompareTag("Player") || Input.GetKeyDown(KeyCode.C))
{
if(cameraPlayer.gameObject.activeSelf)
{
cameraPlayer.gameObject.SetActive(false);
CameraCanhao.gameObject.SetActive(true);
}
}
}
Run Code Online (Sandbox Code Playgroud)
但他并没有尊重按下C键的条件,只是简单地在玩家进入扳机时切换镜头。我忘记了什么?
我是 Unity3d 的新手,我有一个包含 6 个四边形的预制件,使其成为一个立方体。我想将图像纹理添加到立方体的不同面。我从网络服务获取图像,所以我必须在脚本中添加或更改材料。我面临的问题是,我无法在 gameObject 中找到材料属性。
我试过下面的代码:
using UnityEngine;
using System.Collections;
public class shelfRuntime : MonoBehaviour {
public GameObject bottle;
public GameObject newBottle;
// Use this for initialization
void Start () {
iterateChildren(newBottle.transform.root);
GameObject rocketClone = (GameObject)Instantiate(bottle, bottle.transform.position, bottle.transform.rotation);
rocketClone.transform.localScale += new Vector3(1, 1, 1);
GameObject newBottleInMaking = (GameObject)Instantiate(newBottle, newBottle.transform.position, newBottle.transform.rotation);
Transform[] allChildren = newBottleInMaking.GetComponentsInChildren<Transform>();
foreach (Transform child in allChildren)
{
// do whatever with child transform here
}
}
void iterateChildren(Transform trans)
{
Debug.Log(trans.name);
if (trans.name == "Back") …Run Code Online (Sandbox Code Playgroud) 我对Unity相当陌生,但是我已经找到了解决方法。但是,我遇到了一个问题,无论我用多少谷歌搜索,我似乎都找不到有效的解决方案。我可能只是在做一些愚蠢的事情。任何帮助,将不胜感激。我发布到了Unity论坛,但是没有人回应,所以我想我也会给Stack Overflow一个机会。
所以我想做的是在Unity中创建2D地图。该地图将用于在3D世界中导航。该地图必须是可点击的,因为我将从世界地图开始,然后根据用户的点击,将地图更改为该国家/地区的地图。我曾与不同的人交谈过,我想使用的方式是使用shapefile,因为它们已经包含了有关国家和州边界的信息。另外,我知道将来我将不得不使用shapefile,所以我认为现在可以对它们进行一些练习。我想从小处着手,所以我下载了一个zip文件,其中包含美国的shapefile。我按照论坛的说明下载了QGIS,并在该软件中打开了shapefile。在QGIS中,我能够突出显示各个状态,如下图所示
现在,我希望在Unity中具有相同的功能,除了我不仅要突出显示它,还希望它可以单击并能够将其标识为蒙大拿州。
因此,从这里我可以将该文件转换为DXF,然后将其转换为FBX。但是在那之后我迷路了。我不确定我是否必须进行这些转换。
如果有人可以帮助我,我将不胜感激!同样,我是Unity新手,所以如果您能牢记这一点,我将不胜感激。
我想直接在代码中将裤子的颜色从蓝色(#0088f0)更改为红色(#f00000)(这是2D精灵)。
我进行了很多搜索,但未找到无需重新着色特定像素(setPixel()).. ect。的精灵对象。
我们不能以某种方式仅将颜色替换为精灵上的另一种颜色吗?例如,对于此精灵,默认情况下BLUE的RGB渲染等于RED?
I've got problem with UI listener. I try to assign click listener to the method in for loop for UI, but every time I've got last option selected.
public Button[] options;
void Start ()
{
for(int i = 0; i < options.Length; i++)
{
options[i].onClick.AddListener(()=> {OptionPressed(i);});
}
}
private void OptionPressed(int i)
{
print (i);
}
Run Code Online (Sandbox Code Playgroud)
It's always print 3. My question is why? and also why 3 while there is only 3 buttons, so it should be 2?
我有一个基于 Unity 的游戏,可以玩超过 3-5 分钟。所以,我想要一组可以依次播放的歌曲(至少 2 首)。
我知道如何将一个特定的音频源设置到场景的主摄像机并将其设置为循环;但这会很单调,所以我想知道如何将一组歌曲添加到特定场景并按顺序播放它们?
任何帮助将不胜感激。谢谢。
我有一Component节课:
class Component
{
}
Run Code Online (Sandbox Code Playgroud)
然后是一个Collider继承自它的类:
class Collider :public Component
{
}
Run Code Online (Sandbox Code Playgroud)
并且SphereCollider继承自Collider:
class SphereCollider :public Collider
{
}
Run Code Online (Sandbox Code Playgroud)
最后,GameObject您可以使用添加或删除组件的类.
该GameObject.h标题:
class GameObject
{
//Add functionality
template <class T>
T& AddComponent();
//Get functionality
template <typename T>
T& GetComponent();
}
Run Code Online (Sandbox Code Playgroud)
该GameObject.cpp来源:
template <typename T>
T& GameObject::AddComponent(){}
template <typename T>
T& GameObject::GetComponent(){}
//Explicit instantiation
template Component &GameObject::GetComponent<Component>();
template Component &GameObject::AddComponent<Component>();
template SphereCollider &GameObject::GetComponent<SphereCollider>();
template SphereCollider &GameObject::AddComponent<SphereCollider>();
Run Code Online (Sandbox Code Playgroud)
一切都很好.我可以在没有指针的情况下从GameObject添加或获取组件,如下所示:
GameObject …Run Code Online (Sandbox Code Playgroud) 在 Unity 中,如何引用 SpaceBar 键以便在按下空格键时对对象施加力?
void Update()
{
rb.AddForce(0, 0, forwardforce * Time.deltaTime);
if (Input.GetKey("a"))
{
rb.AddForce(500 * Time.deltaTime, 0, 0);
}
if (Input.GetKey("w"))
{
rb.AddForce(0, 0, -500 * Time.deltaTime);
}
if (Input.GetKey("s"))
{
rb.AddForce(0, 0, 500 * Time.deltaTime);
}
if (Input.GetKey("d"))
{
rb.AddForce(-500 * Time.deltaTime, 0, 0);
}
if (Input.GetKey("vbKeySpace"))
{
rb.AddForce(0, 300 * Time.deltaTime, 0);
}
}
Run Code Online (Sandbox Code Playgroud) 我拼命地寻找到解决该问题的方法,但还没有找到任何可能的办法,也许您可以帮帮我:我正在做一个简单的测试,其中一种圆柱体可以自行旋转并通过摩擦在平坦的平台上移动。我有刚体,已经附加了网格对撞机和控制旋转的脚本。它可以快慢移动,取决于其转速。脚本如下:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerController : MonoBehaviour {
public float rollingSpeed;
public float gravity;
// Update is called once per frame
void FixedUpdate()
{
transform.Rotate(rollingSpeed, 0.0f, 0.0f);
GetComponent<Rigidbody>().AddForce(0.0f, -gravity, 0.0f);
}
}
Run Code Online (Sandbox Code Playgroud)
问题是当我运行“播放”模式时,此圆柱体本身正在旋转,但保持在相同位置!(实际上,它来回移动的幅度很小),我真的不知道是什么原因,我试图增加摩擦参数,添加物理材料,甚至向下施加第二个力(如重力),但没有用。有人可以为此提供解决方案吗?非常感谢你们!
如何在Unity 2018.2+中为Android设备开发的程序中获取C#的IP地址?
似乎Network.player.ipAddress现在已经弃用了,所以我正在寻找一种新的方式.
c# ×9
c++ ×1
colors ×1
game-physics ×1
interactive ×1
ip ×1
ip-address ×1
renderer ×1
shape ×1
sprite ×1
templates ×1