当前位置: 首页>>代码示例>>C#>>正文


C# GameObject.LookAt方法代码示例

本文整理汇总了C#中UnityEngine.GameObject.LookAt方法的典型用法代码示例。如果您正苦于以下问题:C# GameObject.LookAt方法的具体用法?C# GameObject.LookAt怎么用?C# GameObject.LookAt使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在UnityEngine.GameObject的用法示例。


在下文中一共展示了GameObject.LookAt方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: SpawnEdge

 protected virtual Transform SpawnEdge()
 {
     Transform transform = new GameObject("WallChunk").transform;
     transform.transform.position = this._p1;
     Vector3 b = new Vector3(0f, this._logWidth * 0.95f, 0f);
     Vector3 vector = this._p2 - this._p1;
     Quaternion rotation = Quaternion.LookRotation(vector);
     Vector3 vector2 = this._p1;
     transform.position = this._p1;
     transform.LookAt(this._p2);
     Vector3 localScale = new Vector3(1f, 1f, vector.magnitude / this._logLength);
     Vector3 localScale2 = new Vector3(1f, 1f, 0.31f + (localScale.z - 1f) / 2f);
     float d = 1f - localScale2.z / localScale.z;
     for (int i = 0; i < 5; i++)
     {
         Transform transform2 = this.NewLog(vector2, rotation);
         transform2.parent = transform;
         WallChunkArchitect.Additions addition = this._addition;
         switch (addition + 1)
         {
         case WallChunkArchitect.Additions.Window:
             transform2.localScale = localScale;
             break;
         case WallChunkArchitect.Additions.Door1:
             if (i == 2 || i == 3)
             {
                 transform2.localScale = localScale2;
                 Transform transform3 = this.NewLog(vector2 + vector * d, rotation);
                 transform3.parent = transform2;
                 transform3.localScale = Vector3.one;
             }
             else
             {
                 transform2.localScale = localScale;
             }
             break;
         case WallChunkArchitect.Additions.Door2:
         case WallChunkArchitect.Additions.LockedDoor1:
         case WallChunkArchitect.Additions.LockedDoor2:
         case (WallChunkArchitect.Additions)5:
             if (i < 4)
             {
                 transform2.localScale = localScale2;
                 Transform transform4 = this.NewLog(vector2 + vector * d, rotation);
                 transform4.parent = transform2;
                 transform4.localScale = Vector3.one;
             }
             else
             {
                 transform2.localScale = localScale;
             }
             break;
         }
         vector2 += b;
     }
     return transform;
 }
开发者ID:GameDiffs,项目名称:TheForest,代码行数:57,代码来源:WallChunkArchitect.cs

示例2: SpawnEdge

 protected override Transform SpawnEdge()
 {
     Transform transform = new GameObject("FenceChunk").transform;
     transform.position = this._p1;
     transform.LookAt(this._p2);
     Vector3 vector = this._p2 - this._p1;
     Vector3 normalized = Vector3.Scale(vector, new Vector3(1f, 0f, 1f)).normalized;
     float y = Mathf.Tan(Vector3.Angle(vector, normalized) * 0.0174532924f) * this._logWidth * (float)this._spread;
     Quaternion rotation = Quaternion.LookRotation(Vector3.forward);
     Quaternion rhs = Quaternion.FromToRotation(Vector3.up, Vector3.forward);
     Quaternion rotation2 = Quaternion.LookRotation(transform.forward) * rhs;
     bool flag = this._p1.y < this._p2.y;
     float num = Vector3.Distance(this._p1, this._p2);
     int num2 = Mathf.RoundToInt(num / (this._logWidth * (float)this._spread));
     if (num2 > 1)
     {
         num2--;
     }
     Vector3 vector2 = normalized * (num / (float)num2);
     vector2.y = y;
     if (!flag)
     {
         vector2.y *= -1f;
     }
     Vector3 vector3 = this._p1;
     vector3 += vector2 / 2f;
     for (int i = 0; i < num2; i++)
     {
         Transform transform2 = base.NewLog(vector3, rotation);
         transform2.localScale = Vector3.one;
         transform2.parent = transform;
         vector3 += vector2;
     }
     Vector3 vector4 = new Vector3(0f, this._logLength * 0.45f, this._logWidth / 2f);
     Vector3 vector5 = new Vector3(0f, this._logLength * 0.8f, this._logWidth / 2f);
     vector4 += vector2 / 2f;
     vector5 += vector2 / 2f;
     Vector3 localScale = new Vector3(1f, num * 0.335f, 1f);
     Transform transform3 = base.NewLog(this._p1 + vector4, rotation2);
     transform3.parent = transform;
     transform3.localScale = localScale;
     transform3 = base.NewLog(this._p1 + vector5, rotation2);
     transform3.parent = transform;
     transform3.localScale = localScale;
     return transform;
 }
开发者ID:GameDiffs,项目名称:TheForest,代码行数:46,代码来源:StickFenceChunkArchitect.cs

示例3: SpawnEdge

 protected override Transform SpawnEdge()
 {
     Transform transform = new GameObject("FenceChunk").transform;
     transform.position = this._p1;
     transform.LookAt(this._p2);
     Vector3 vector = this._p1;
     Vector3 vector2 = this._p2 - this._p1;
     Vector3 normalized = Vector3.Scale(vector2, new Vector3(1f, 0f, 1f)).normalized;
     float y = Mathf.Tan(Vector3.Angle(vector2, normalized) * 0.0174532924f) * this._offset;
     Quaternion rotation = Quaternion.LookRotation(-vector2);
     bool flag = this._p1.y < this._p2.y;
     float num = Vector3.Distance(this._p1, this._p2);
     int i = Mathf.RoundToInt(num / this._offset);
     if (i < 1)
     {
         i = 1;
     }
     Vector3 a = normalized * this._offset;
     a.y = y;
     if (!flag)
     {
         a.y *= -1f;
     }
     vector.y -= 0.15f;
     while (i > 0)
     {
         int num2 = Mathf.Min(i, 5);
         i -= num2;
         Transform transform2;
         if (!this._wasBuilt)
         {
             if (!this._wallRoot)
             {
                 transform2 = (Transform)UnityEngine.Object.Instantiate(Prefabs.Instance.RockFenceChunksGhostPrefabs[num2 - 1], vector, rotation);
             }
             else
             {
                 transform2 = (Transform)UnityEngine.Object.Instantiate(Prefabs.Instance.RockFenceChunksGhostFillPrefabs[num2 - 1], vector, rotation);
             }
         }
         else
         {
             transform2 = (Transform)UnityEngine.Object.Instantiate(Prefabs.Instance.RockFenceChunksBuiltPrefabs[num2 - 1], vector, rotation);
         }
         transform2.parent = transform;
         vector += a * (float)num2;
     }
     return transform;
 }
开发者ID:GameDiffs,项目名称:TheForest,代码行数:49,代码来源:RockFenceChunkArchitect.cs

示例4: SpawnEdge

 protected override Transform SpawnEdge(WallArchitect.Edge edge)
 {
     Transform transform = new GameObject("StickFenceEdge").transform;
     transform.transform.position = edge._p1;
     transform.LookAt(edge._p2);
     Quaternion rotation = Quaternion.LookRotation(Vector3.forward);
     Quaternion rhs = Quaternion.FromToRotation(Vector3.up, Vector3.forward);
     for (int i = 0; i < edge._segments.Length; i++)
     {
         WallArchitect.HorizontalSegment horizontalSegment = edge._segments[i];
         Vector3 vector = horizontalSegment._p1;
         Vector3 vector2 = horizontalSegment._p2 - horizontalSegment._p1;
         Vector3 normalized = Vector3.Scale(vector2, new Vector3(1f, 0f, 1f)).normalized;
         float y = Mathf.Tan(Vector3.Angle(vector2, normalized) * 0.0174532924f) * this._logWidth * (float)this._spread;
         Transform transform2 = new GameObject("S" + i).transform;
         transform2.parent = transform;
         transform2.position = horizontalSegment._p1;
         transform2.LookAt(horizontalSegment._p2);
         horizontalSegment._root = transform2;
         bool flag = horizontalSegment._p1.y < horizontalSegment._p2.y;
         float num = Vector3.Distance(horizontalSegment._p1, horizontalSegment._p2);
         int num2 = Mathf.RoundToInt(num / (this._logWidth * (float)this._spread));
         if (num2 > 1)
         {
             num2--;
         }
         else
         {
             num2 = 1;
         }
         Vector3 vector3 = normalized * (num / (float)num2);
         vector3.y = y;
         if (!flag)
         {
             vector3.y *= -1f;
         }
         vector += vector3 / 2f;
         for (int j = 0; j < num2; j++)
         {
             Transform transform3 = base.NewLog(vector, rotation);
             transform3.localScale = Vector3.one;
             transform3.parent = transform2;
             this._newPool.Enqueue(transform3);
             vector += vector3;
         }
         Vector3 vector4 = new Vector3(0f, this._logLength * 0.45f, this._logWidth / 2f);
         Vector3 vector5 = new Vector3(0f, this._logLength * 0.8f, this._logWidth / 2f);
         vector4 += vector3 / 2f;
         vector5 += vector3 / 2f;
         Vector3 localScale = new Vector3(1f, num * 0.335f, 1f);
         Quaternion rotation2 = Quaternion.LookRotation(transform2.forward) * rhs;
         Debug.DrawRay(horizontalSegment._p1 + vector4, -transform2.up, Color.red);
         Transform transform4 = base.NewLog(horizontalSegment._p1 + vector4, rotation2);
         transform4.parent = transform2;
         transform4.localScale = localScale;
         this._newPool.Enqueue(transform4);
         transform4 = base.NewLog(horizontalSegment._p1 + vector5, rotation2);
         transform4.parent = transform2;
         transform4.localScale = localScale;
         this._newPool.Enqueue(transform4);
     }
     return transform;
 }
开发者ID:GameDiffs,项目名称:TheForest,代码行数:63,代码来源:StickFenceArchitect.cs

示例5: SpawnEdge

 protected override Transform SpawnEdge()
 {
     Transform transform = new GameObject("FenceChunk").transform;
     transform.position = this._p1;
     transform.LookAt(this._p2);
     Quaternion rhs = Quaternion.FromToRotation(Vector3.up, Vector3.forward);
     Vector3 position = this._p1;
     Vector3 vector = Vector3.Lerp(this._p1, this._p2, 0.5f);
     Vector3 vector2 = new Vector3(0f, this._logLength, 0f);
     Vector3 vector3 = this._p2 - this._p1;
     Vector3 normalized = Vector3.Scale(vector3, new Vector3(1f, 0f, 1f)).normalized;
     float y = Mathf.Tan(Vector3.Angle(vector3, normalized) * 0.0174532924f) * this._logWidth * (float)this._spread;
     transform.position = this._p1;
     transform.LookAt(this._p2);
     bool flag = this._p1.y < this._p2.y;
     float num = Vector3.Distance(this._p1, this._p2);
     int num2 = 4;
     Vector3 vector4 = normalized * (num / (float)num2);
     vector4.y = y;
     if (!flag)
     {
         vector4.y *= -1f;
     }
     for (int i = 0; i < num2; i++)
     {
         Transform transform2;
         switch (i)
         {
         case 0:
             transform2 = base.NewLog(position, Quaternion.LookRotation(Vector3.Lerp(this._p1, this._p2, 0.1f) + vector2 - this._p1) * rhs);
             Debug.DrawLine(Vector3.Lerp(this._p1, this._p2, 0.1f) + vector2, this._p1, Color.red);
             break;
         case 1:
             position = vector;
             transform2 = base.NewLog(position, Quaternion.LookRotation(Vector3.Lerp(this._p1, this._p2, 0.35f) + vector2 - vector) * rhs);
             Debug.DrawLine(Vector3.Lerp(this._p1, this._p2, 0.35f) + vector2, vector, Color.blue);
             break;
         case 2:
             position = vector;
             transform2 = base.NewLog(position, Quaternion.LookRotation(Vector3.Lerp(this._p1, this._p2, 0.7f) + vector2 - vector) * rhs);
             Debug.DrawLine(Vector3.Lerp(this._p1, this._p2, 0.7f) + vector2, vector, Color.green);
             break;
         default:
             position = this._p2;
             transform2 = base.NewLog(position, Quaternion.LookRotation(Vector3.Lerp(this._p1, this._p2, 0.9f) + vector2 - this._p2) * rhs);
             Debug.DrawLine(Vector3.Lerp(this._p1, this._p2, 0.9f) + vector2, this._p2, Color.yellow);
             break;
         }
         transform2.name = "v" + i;
         transform2.parent = transform;
     }
     Vector3 vector5 = new Vector3(0f, this._logLength * 0.4f, this._logWidth / 2f);
     Vector3 b = vector5 + (this._p2 - this._p1) / 2f;
     Quaternion rotation = Quaternion.LookRotation(vector + vector2 * 0.6f - (this._p1 + vector5)) * rhs;
     Transform transform3 = base.NewLog(this._p1 + vector5, rotation);
     transform3.name = "h1";
     transform3.parent = transform;
     transform3 = base.NewLog(this._p1 + b, rotation);
     transform3.name = "h2";
     transform3.parent = transform;
     Quaternion rotation2 = Quaternion.LookRotation(this._p1 + vector2 * 0.8f - vector) * rhs;
     Transform transform4 = base.NewLog(vector, rotation2);
     transform4.name = "d1";
     transform4.parent = transform;
     transform4 = base.NewLog(this._p2, rotation2);
     transform4.name = "d2";
     transform4.parent = transform;
     return transform;
 }
开发者ID:GameDiffs,项目名称:TheForest,代码行数:69,代码来源:BoneFenceChunkArchitect.cs

示例6: CreateStructure

 public void CreateStructure(bool isRepair = false, bool addColliders = true)
 {
     if (this._wasBuilt && isRepair)
     {
         if (this._bridgeRoot)
         {
             UnityEngine.Object.Destroy(this._bridgeRoot.gameObject);
         }
         this._bridgeRoot = null;
         base.StartCoroutine(this.DelayedAwake(true));
     }
     GameObject gameObject = (!this._bridgeRoot) ? null : this._bridgeRoot.gameObject;
     this._bridgeRoot = this.CreateBridge(this._anchor1.transform.position, this._anchor2.transform.position);
     this._bridgeRoot.name = "BridgeRoot" + ((!addColliders) ? "Ghost" : "Built");
     this._bridgeRoot.parent = base.transform;
     if (gameObject)
     {
         UnityEngine.Object.Destroy(gameObject);
     }
     if (addColliders)
     {
         base.transform.position = this._anchor1.transform.position;
         this._bridgeRoot.parent = base.transform;
         Vector3 vector = this._bridgeRoot.GetChild(0).position;
         int num = Mathf.CeilToInt(Vector3.Distance(this._anchor1.transform.position, this._anchor2.transform.position) / this._maxColliderLength);
         int num2 = Mathf.CeilToInt((float)this._bridgeRoot.childCount / (float)num);
         for (int i = 1; i <= num; i++)
         {
             int num3 = num2 * i;
             if (num3 >= this._bridgeRoot.childCount)
             {
                 num3 = this._bridgeRoot.childCount - 1;
             }
             Transform child = this._bridgeRoot.GetChild(num3);
             Vector3 position = child.position;
             Transform transform = new GameObject("Floor" + i).transform;
             transform.parent = base.transform;
             transform.position = vector;
             transform.LookAt(position);
             BoxCollider boxCollider = transform.gameObject.AddComponent<BoxCollider>();
             boxCollider.center = transform.InverseTransformPoint(Vector3.Lerp(vector, position, 0.5f));
             boxCollider.size = new Vector3(4.5f, this._logWidth, Vector3.Distance(vector, position));
             transform.tag = "UnderfootWood";
             vector = position;
         }
     }
     if (this._wasBuilt && isRepair)
     {
         this._bridgeRoot.parent = base.transform;
     }
 }
开发者ID:GameDiffs,项目名称:TheForest,代码行数:51,代码来源:BridgeArchitect.cs

示例7: SpawnEdge

 protected override Transform SpawnEdge(WallArchitect.Edge edge)
 {
     Transform transform = new GameObject("StickFenceEdge").transform;
     transform.transform.position = edge._p1;
     transform.LookAt(edge._p2);
     Quaternion quaternion = Quaternion.LookRotation(Vector3.forward);
     Quaternion rhs = Quaternion.FromToRotation(Vector3.up, Vector3.forward);
     for (int i = 0; i < edge._segments.Length; i++)
     {
         WallArchitect.HorizontalSegment horizontalSegment = edge._segments[i];
         Vector3 position = horizontalSegment._p1;
         Vector3 vector = Vector3.Lerp(horizontalSegment._p1, horizontalSegment._p2, 0.5f);
         Vector3 vector2 = new Vector3(0f, this._logLength, 0f);
         Vector3 vector3 = horizontalSegment._p2 - horizontalSegment._p1;
         Vector3 normalized = Vector3.Scale(vector3, new Vector3(1f, 0f, 1f)).normalized;
         float y = Mathf.Tan(Vector3.Angle(vector3, normalized) * 0.0174532924f) * this._logWidth * (float)this._spread;
         Transform transform2 = new GameObject("S" + i).transform;
         transform2.parent = transform;
         transform2.position = horizontalSegment._p1;
         transform2.LookAt(horizontalSegment._p2);
         horizontalSegment._root = transform2;
         bool flag = horizontalSegment._p1.y < horizontalSegment._p2.y;
         float num = Vector3.Distance(horizontalSegment._p1, horizontalSegment._p2);
         int num2 = 4;
         Vector3 vector4 = normalized * (num / (float)num2);
         vector4.y = y;
         if (!flag)
         {
             vector4.y *= -1f;
         }
         for (int j = 0; j < num2; j++)
         {
             Transform transform3;
             switch (j)
             {
             case 0:
                 transform3 = base.NewLog(position, Quaternion.LookRotation(Vector3.Lerp(horizontalSegment._p1, horizontalSegment._p2, 0.1f) + vector2 - horizontalSegment._p1) * rhs);
                 Debug.DrawLine(Vector3.Lerp(horizontalSegment._p1, horizontalSegment._p2, 0.1f) + vector2, horizontalSegment._p1, Color.red);
                 break;
             case 1:
                 position = vector;
                 transform3 = base.NewLog(position, Quaternion.LookRotation(Vector3.Lerp(horizontalSegment._p1, horizontalSegment._p2, 0.35f) + vector2 - vector) * rhs);
                 Debug.DrawLine(Vector3.Lerp(horizontalSegment._p1, horizontalSegment._p2, 0.35f) + vector2, vector, Color.blue);
                 break;
             case 2:
                 position = vector;
                 transform3 = base.NewLog(position, Quaternion.LookRotation(Vector3.Lerp(horizontalSegment._p1, horizontalSegment._p2, 0.7f) + vector2 - vector) * rhs);
                 Debug.DrawLine(Vector3.Lerp(horizontalSegment._p1, horizontalSegment._p2, 0.7f) + vector2, vector, Color.green);
                 break;
             default:
                 position = horizontalSegment._p2;
                 transform3 = base.NewLog(position, Quaternion.LookRotation(Vector3.Lerp(horizontalSegment._p1, horizontalSegment._p2, 0.9f) + vector2 - horizontalSegment._p2) * rhs);
                 Debug.DrawLine(Vector3.Lerp(horizontalSegment._p1, horizontalSegment._p2, 0.9f) + vector2, horizontalSegment._p2, Color.yellow);
                 break;
             }
             transform3.name = "v" + j;
             transform3.parent = transform2;
             this._newPool.Enqueue(transform3);
         }
         Vector3 vector5 = new Vector3(0f, this._logLength * 0.4f, this._logWidth / 2f);
         Vector3 b = vector5 + (horizontalSegment._p2 - horizontalSegment._p1) / 2f;
         Quaternion rotation = Quaternion.LookRotation(vector + vector2 * 0.6f - (horizontalSegment._p1 + vector5)) * rhs;
         Transform transform4 = base.NewLog(horizontalSegment._p1 + vector5, rotation);
         transform4.name = "h1";
         transform4.parent = transform2;
         this._newPool.Enqueue(transform4);
         transform4 = base.NewLog(horizontalSegment._p1 + b, rotation);
         transform4.name = "h2";
         transform4.parent = transform2;
         this._newPool.Enqueue(transform4);
         Quaternion rotation2 = Quaternion.LookRotation(horizontalSegment._p1 + vector2 * 0.8f - vector) * rhs;
         Transform transform5 = base.NewLog(vector, rotation2);
         transform5.name = "d1";
         transform5.parent = transform2;
         this._newPool.Enqueue(transform5);
         transform5 = base.NewLog(horizontalSegment._p2, rotation2);
         transform5.name = "d2";
         transform5.parent = transform2;
         this._newPool.Enqueue(transform5);
     }
     return transform;
 }
开发者ID:GameDiffs,项目名称:TheForest,代码行数:82,代码来源:BoneFenceArchitect.cs

示例8: SpawnEdge

 protected virtual Transform SpawnEdge(WallArchitect.Edge edge)
 {
     Transform transform = new GameObject("WallEdge").transform;
     transform.transform.position = edge._p1;
     Vector3 b = new Vector3(0f, this._logWidth * 0.95f, 0f);
     for (int i = 0; i < edge._segments.Length; i++)
     {
         WallArchitect.HorizontalSegment horizontalSegment = edge._segments[i];
         Quaternion rotation = Quaternion.LookRotation(horizontalSegment._axis);
         Vector3 vector = horizontalSegment._p1;
         Transform transform2 = new GameObject("Segment" + i).transform;
         transform2.parent = transform;
         transform2.LookAt(horizontalSegment._axis);
         horizontalSegment._root = transform2;
         transform2.position = horizontalSegment._p1;
         Vector3 localScale = new Vector3(1f, 1f, horizontalSegment._length / this._logLength);
         Vector3 vector2 = new Vector3(1f, 1f, 0.31f + (localScale.z - 1f) / 2f);
         float num = 1f - vector2.z / localScale.z;
         for (int j = 0; j < 5; j++)
         {
             Transform transform3 = this.NewLog(vector, rotation);
             transform3.parent = transform2;
             this._newPool.Enqueue(transform3);
             transform3.localScale = localScale;
             vector += b;
         }
     }
     return transform;
 }
开发者ID:GameDiffs,项目名称:TheForest,代码行数:29,代码来源:WallArchitect.cs

示例9: SpawnEdge

 protected override Transform SpawnEdge()
 {
     Transform transform = new GameObject("WallChunk").transform;
     transform.transform.position = this._p1;
     Vector3 vector = this._p2 - this._p1;
     Vector3 normalized = Vector3.Scale(vector, new Vector3(1f, 0f, 1f)).normalized;
     float y = Mathf.Tan(Vector3.Angle(vector, normalized) * 0.0174532924f) * this._logWidth;
     Quaternion rotation = Quaternion.LookRotation(Vector3.forward);
     float num = Vector3.Distance(this._p1, this._p2);
     int num2 = Mathf.RoundToInt(num / this._logWidth);
     Vector3 b = normalized * num / (float)num2;
     b.y = y;
     if (vector.y < 0f)
     {
         b.y *= -1f;
     }
     Vector3 vector2 = this._p1;
     transform.position = this._p1;
     transform.LookAt(this._p2);
     for (int i = 0; i < num2; i++)
     {
         Transform transform2 = base.NewLog(vector2, rotation);
         transform2.parent = transform;
         vector2 += b;
     }
     return transform;
 }
开发者ID:GameDiffs,项目名称:TheForest,代码行数:27,代码来源:WallDefensiveChunkArchitect.cs


注:本文中的UnityEngine.GameObject.LookAt方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。