在Update()中比较位置时,对象没有实例化

时间:2018-01-27 11:47:06

标签: c# unity3d unity5

我将此脚本附加到主摄像头。我想在摄像机位于y轴的特定位置时实例化一个对象。但是对象没有实例化。这是剧本。

public GameObject obj;

private void Update()
{
    if (transform.position.y % 2 == 0) {

    Instantiate(obj, new Vector3(transform.position.x, transform.position.y), Quaternion.identity);

   }

}

是否与模数函数有关? 谢谢!

1 个答案:

答案 0 :(得分:1)

它没有实例化,因为if (transform.position.y % 2 == 0) {不是trueif (transform.position.y % 2 == 0)未评估为true的原因是因为transform.position.yfloat。将float除以2时,余数可能不是0

在将floatint进行比较之前,0 Convert.ToInt32 Math.Round if (Convert.ToInt32(transform.position.y) % 2 == 0) { //Instantiate } 。这可以通过static std::map<std::string,int> wordDictionary = { { "alpha", 0 }, { "beta", 0 }, { "gamma", 0 } ... }; operations = [ migrations.RunSQL( 'ALTER TABLE "agency" ADD COLUMN "email" varchar(254) NULL;ALTER TABLE "agency" ALTER COLUMN "email" DROP DEFAULT;COMMIT;', ), migrations.RunSQL( "UPDATE agency SET email= Concat(country_code, '@example.fr');COMMIT;", ), migrations.RunSQL( 'ALTER TABLE "agency" ALTER COLUMN "email" SET NOT NULL;ALTER TABLE "agency" ADD CONSTRAINT "agency_email_b551ad2a_uniq" UNIQUE ("email");ALTER TABLE "agency" ALTER COLUMN "email" DROP DEFAULT;CREATE INDEX "agency_email_b551ad2a_like" ON "agency" ("email" varchar_pattern_ops);COMMIT;' ) ] 来完成。还有其他方法可以做到这一点。

\documentclass[tikz,border=2mm]{standalone}

\begin{document}

\begin{tikzpicture}
% left box
\filldraw [fill=yellow, draw=black, ultra thick] (0,0) rectangle (8,-10);
\filldraw [fill=white, draw=black, ultra thick] (2,-2) rectangle (6,-5);
\filldraw [fill=white, draw=black, ultra thick] (2,-5) rectangle (6,-8);
\node at (4,-3.5) [font=\sffamily] {\Huge One};
\node at (4,-6.5) [font=\sffamily] {\Huge Two};
% right box
\filldraw [fill=white, draw=black, ultra thick] (12,0) rectangle (20,-10);
\filldraw [fill=yellow, draw=black, ultra thick] (13,-1) rectangle (19,-6);
\node at (16,-3.5) [font=\sffamily] {\Huge Four};
% labels
\node at (4,-11) {\Huge 1};
\node at (16,-11) {\Huge 2};
\node at (16,-7) {\Huge 3};
% lines
\draw [ultra thick] (8,-5) -- (12,-5);
\draw [loosely dashed, ultra thick] (6,-3.5) -- (12,-4);
\draw [loosely dashed, ultra thick] (6,-6.5) -- (12,-6);
\end{tikzpicture}

\end{document}