无论设置备用点如何,衍生单位总是移动到相同的目标(Spawned Units always move to same target regardless of setting alternate points)
我对团结是新的,我正试图创造一个新的游戏。
using UnityEngine; using System.Collections; public class Enemyblue1script : MonoBehaviour { // Use this for initialization public float speed; // speed variable public float RotSpeed = 90f; public GameObject RocketGO; // Reference to our main character Rocket void Start () {} void Update() { Vector2 Pos = new Vector2 (-10, 5); gameObject.transform.position = Vector3.MoveTowards (gameObject.transform.position, Pos, speed * Time.deltaTime); Invoke ("MoveFace", 2f); } void MoveFace() { if( RocketGO == null) { GameObject go = GameObject.FindGameObjectWithTag("Rocket"); if(go != null){ RocketGO = go ;} } if( RocketGO == null) return; Vector3 dir = RocketGO.transform.position - gameObject.transform.position; dir.Normalize(); float zAngle = Mathf.Atan2(dir.x , dir.y) * Mathf.Rad2Deg + 360; Quaternion desiredRot = Quaternion.Euler(0 ,0,-zAngle); gameObject.transform.rotation = Quaternion.RotateTowards(gameObject.transform.rotation , desiredRot , RotSpeed * Time.deltaTime); } }
这是我将敌人移动到某个点的脚本(使用MoveTowards功能)并将敌人旋转到玩家方向。 我还有一个脚本是用来产生这些敌人(一次有两个敌人)脚本
using UnityEngine; using System.Collections; public class Enemy1Spawner : MonoBehaviour { //our meteorite prefab public GameObject Enemy1blue; public float speed; public GameObject p1; public GameObject p2; // Use this for initialization void Start () {} // Update is called once per frame void Update () {} void SpawnEnemy1blue() { //bottom left point of screen //Vector2 min = Camera.main.ViewportToWorldPoint (new Vector2 (0, 0)); //top right point of screen //Vector2 max = Camera.main.ViewportToWorldPoint (new Vector2 (1, 1)); GameObject Enemy1ablue = (GameObject)Instantiate (Enemy1blue); GameObject Enemy2ablue = (GameObject)Instantiate (Enemy1blue); Enemy1ablue.transform.position = new Vector2 (-11,9); Enemy2ablue.transform.position = new Vector2 (11,9); } public void startEnemy1blueSpawner() { Debug.Log ("Invoked Spawning Blue Enemy"); InvokeRepeating ("SpawnEnemy1blue",5f,30f); } //function to stop spawning when game over public void StopEnemy1blueSpawning() { CancelInvoke ("SpawnEnemy1blue"); } }
所以现在虽然产生了敌人! 我的敌人只朝着一个点移动,即
Vector2 Pos = new Vector2 (-10, 5);
我在Updat()
方法中定义了Enemyblue1script
,并且我想在Vector2 Pos = new Vector2 (-10, 5)
(在左侧)的不同位置产生两个敌人; 一个在Vector2 Pos = new Vector2 (10, 5)
(在右侧);通过使用这两个脚本,我能够同时产生两个敌人,但他们都移动到同一点,这是我不想发生的事情。 我已经尝试过像
ENEMY1SPAWNER
脚本>SpawnEnemy1blue()
函数中的东西,我也创建了两个使用vector2的点,并且我为两个不同的敌人调用了两个Movetowards
函数,但不工作,他们没有移动。Vector2 Pos1 = new Vector2 (-10, 5); Vector2 Pos2 = new Vector2 (10, 5); GameObject Enemy1ablue = (GameObject)Instantiate (Enemy1blue); GameObject Enemy2ablue = (GameObject)Instantiate (Enemy1blue); Enemy1ablue.transform.position = new Vector2 (-11,9); Enemy2ablue.transform.position = new Vector2 (11,9); Enemy1ablue.transform.position = Vector3.MoveTowards (Enemy1ablue.transform.position, Pos1, speed * Time.deltaTime); Enemy2ablue.transform.position = Vector3.MoveTowards (Enemy2ablue.transform.position, Pos2, speed * Time.deltaTime);
I am new to unity and i am trying to create a new game.
using UnityEngine; using System.Collections; public class Enemyblue1script : MonoBehaviour { // Use this for initialization public float speed; // speed variable public float RotSpeed = 90f; public GameObject RocketGO; // Reference to our main character Rocket void Start () {} void Update() { Vector2 Pos = new Vector2 (-10, 5); gameObject.transform.position = Vector3.MoveTowards (gameObject.transform.position, Pos, speed * Time.deltaTime); Invoke ("MoveFace", 2f); } void MoveFace() { if( RocketGO == null) { GameObject go = GameObject.FindGameObjectWithTag("Rocket"); if(go != null){ RocketGO = go ;} } if( RocketGO == null) return; Vector3 dir = RocketGO.transform.position - gameObject.transform.position; dir.Normalize(); float zAngle = Mathf.Atan2(dir.x , dir.y) * Mathf.Rad2Deg + 360; Quaternion desiredRot = Quaternion.Euler(0 ,0,-zAngle); gameObject.transform.rotation = Quaternion.RotateTowards(gameObject.transform.rotation , desiredRot , RotSpeed * Time.deltaTime); } }
This is my script for Moving Enemy towards some point (using MoveTowards funtion) and rotating enemy to Players direction. And i have one more script that is for Spawning these enemeies (Two Enemies at a time ) Script is
using UnityEngine; using System.Collections; public class Enemy1Spawner : MonoBehaviour { //our meteorite prefab public GameObject Enemy1blue; public float speed; public GameObject p1; public GameObject p2; // Use this for initialization void Start () {} // Update is called once per frame void Update () {} void SpawnEnemy1blue() { //bottom left point of screen //Vector2 min = Camera.main.ViewportToWorldPoint (new Vector2 (0, 0)); //top right point of screen //Vector2 max = Camera.main.ViewportToWorldPoint (new Vector2 (1, 1)); GameObject Enemy1ablue = (GameObject)Instantiate (Enemy1blue); GameObject Enemy2ablue = (GameObject)Instantiate (Enemy1blue); Enemy1ablue.transform.position = new Vector2 (-11,9); Enemy2ablue.transform.position = new Vector2 (11,9); } public void startEnemy1blueSpawner() { Debug.Log ("Invoked Spawning Blue Enemy"); InvokeRepeating ("SpawnEnemy1blue",5f,30f); } //function to stop spawning when game over public void StopEnemy1blueSpawning() { CancelInvoke ("SpawnEnemy1blue"); } }
So now while Spawning enemies! my enemies are moving towards only one point i.e
Vector2 Pos = new Vector2 (-10, 5);
which I have defined inUpdat()
method ofEnemyblue1script
, and i want to spawn two enemies at a different positions one atVector2 Pos = new Vector2 (-10, 5)
(to the left side); and one atVector2 Pos = new Vector2 (10, 5)
(to the right side);By using these two scripts i am able to spawn two enemies at a time, but they both move to same point, which is what i do not want to happen. I have tried stuff like in
ENEMY1SPAWNER
script >SpawnEnemy1blue()
function i have also created two points using vector2 and i called twoMovetowards
functions there for two different enemies but is not working they are not moving.Vector2 Pos1 = new Vector2 (-10, 5); Vector2 Pos2 = new Vector2 (10, 5); GameObject Enemy1ablue = (GameObject)Instantiate (Enemy1blue); GameObject Enemy2ablue = (GameObject)Instantiate (Enemy1blue); Enemy1ablue.transform.position = new Vector2 (-11,9); Enemy2ablue.transform.position = new Vector2 (11,9); Enemy1ablue.transform.position = Vector3.MoveTowards (Enemy1ablue.transform.position, Pos1, speed * Time.deltaTime); Enemy2ablue.transform.position = Vector3.MoveTowards (Enemy2ablue.transform.position, Pos2, speed * Time.deltaTime);
原文:https://stackoverflow.com/questions/32669707
最满意答案
INT_FAST16_MAX
是可存储在int_fast16_t
变量中的int_fast16_t
。
int_fast16_t
保证是最快的int,大小至少为 16位。由于MSVC的目标机器是32位通用寄存器,其访问速度比16位更快,因此
int_fast16_t
实际上是一个32位整数。 因此,INT_FAST16_MAX
是INT32_MAX
。也可以看看:
INT_FAST16_MAX
is the largest value that can be stored in anint_fast16_t
variable.
int_fast16_t
is guaranteed to be the fastest int with a size of at least 16 bits.Because MSVC is targeting machines that have 32-bit general purpose registers which are faster to access than 16-bit,
int_fast16_t
is actually a 32-bit integer. And thus,INT_FAST16_MAX
isINT32_MAX
.See also:
相关问答
更多-
你的工具链完全坏了。 我建议删除然后重新安装Visual Studio。 Your toolchain is completely broken. I suggest removing then re-installing Visual Studio.
-
对于标准头文件limits.h的INT_MAX ,实现者的手与它需要在预处理程序#if指令中可用的事实相关联。 这排除了涉及sizeof或casts的任何事情。 如果你只是想要一个在实际的C表达式中工作的版本,也许这会起作用: (int)-1U/2 == (int)(-1U/2) ? (int)-1U : (int)(-1U/2) 这里的概念是int可以具有与unsigned相同数量的值位,或者具有更少的值位; C标准允许。 为了测试它是什么,请检查转换结果(int)-1U 。 如果-1U适用于int , ...
-
未能升级VS2015的nuget 这个问题应该是核心visual studio可扩展性中的一个错误或问题。 这不是NuGet特定的问题。 它通常与诸如反病毒或加密服务等相关 。 我想在这里提供一些故障排除: 以管理员身份登录到计算机,并使用管理员启动Visual Studio。 检查您的计算机是否安装了McAfee Endpoint Encryption full-disk encryption product ,而不是防病毒软件。 如果是,则应该从全盘加密中排除devenv.exe和VSIXInstall ...
-
据我所知,这是正确定义的。 宏扩展为与指定类型对应的整数常量表达式,而不是指定类型。 C和C ++都没有比int更窄的类型的整数常量表达式的语法。 它依赖于隐式转换将int表达式转换为需要的较窄类型。 (C ++通过引用C标准包含C头
的内容。最新的C ++标准是指1999 C标准。我不确定三个C99技术勘误的状态是什么C ++。) 看N1570 7.20.4p1: 以下类似函数的宏扩展为整数常量,适用于初始化具有与 定义的类型对应的整数类型的对象。 每个宏名称对应于7. ... -
为什么int16类型限制为32,768,如果最多16位为65,535?(Why is int16 type limit 32,768 if 16 bits max is 65,535?)[2022-04-11]
因为它的范围是-32,768到32,767,其总和是65,536(这里包括0)可能的值。 如果你使用UInt16 (代表unsigned int16),你可以给它一个65,535的值。 Because it ranges from -32,768 to 32,767, which in sum is 65,536 (0 is included here) possible values. If you use UInt16 (which stands for unsigned int16) you can ... -
VS2017和VS2015之间的连接是否存在差异?(Are there differences in the linkers between VS2017 and VS2015?)[2023-04-01]
尝试为链接器指定/SUBSYSTEM:CONSOLE 。 这是因为它可能会搜索WinMain而不是main 。 在项目的属性页中,您可以在Linker / System / SubSystem中设置它并选择Console (/SUBSYSTEM:CONSOLE) (而不是Windows (/SUBSYSTEM:WINDOWS) ) Try to specify /SUBSYSTEM:CONSOLE to the linker. It's because maybe it searches for WinMa ... -
为什么INT_FAST16_MAX被定义为INT32_MAX(VS 2015)?(Why INT_FAST16_MAX is defined as INT32_MAX (VS 2015)?)[2022-06-02]
INT_FAST16_MAX是可存储在int_fast16_t变量中的int_fast16_t 。 int_fast16_t保证是最快的int,大小至少为 16位。 由于MSVC的目标机器是32位通用寄存器,其访问速度比16位更快,因此int_fast16_t实际上是一个32位整数。 因此, INT_FAST16_MAX是INT32_MAX 。 也可以看看: “int”和“int_fast16_t”有什么区别? INT_FAST16_MAX is the largest value that can be ... -
我发现只能为最高版本3的OData服务创建服务引用。 I figured out that service references can only be created for OData service up to version 3.
-
std::function的构造函数用于接受sun下的所有东西(它是一个template
function(F f) )。 然后它受到标准的限制(通过LWG问题2132 ),但实现该约束需要表达SFINAE, 微软的编译器尚不支持 。 std::function's constructor used to accept everything under the sun (it was a template function(F f)). Then it got const ... -
在VS2015中,如果语言环境总是等于传递给构造函数的参数(如果它是有效的),那么他们就是这样命名的: // c:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\xlocinfo line 360 void _Construct(const string &_Str, category _Cat) { // construct a locale with named facets bool _Bad = f ...