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


C# Transform.SetParent方法代码示例

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


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

示例1: Decorate

    public void Decorate()
    {
        prototype = GameObject.CreatePrimitive(PrimitiveType.Sphere).transform;
        prototype.transform.localScale = new Vector3(0.4f, 0.4f, 0.4f);
        parentObject = new GameObject("Visualization").transform;
        parentObject.SetParent(this.gameObject.transform);

        item = prototype;
        prototype.SetParent(parentObject);
        DestroyImmediate(item.gameObject.GetComponent<Collider>());

        if (frequency <= 0)
        {
            return;
        }
        float stepSize = 1f / (frequency * 100);
        for (int p = 0, f = 0; f < frequency; f++)
        {
            for (int i = 0; i < 100; i++, p++)
            {
                Transform curItem = (Transform)Instantiate(item.gameObject).transform;
                curItem.SetParent(parentObject);
                objects.Add(curItem);
                Vector3 position = spline.GetPoint(p * stepSize);
                item.transform.localPosition = position;
                if (lookForward)
                {
                    item.transform.LookAt(position + spline.GetDirection(p * stepSize));
                }
                item.transform.parent = transform;
            }
        }
    }
开发者ID:Schadek,项目名称:Skelevator,代码行数:33,代码来源:SplineDecorator.cs

示例2: BoardSetup

		} //End.InitialisetList()
		
		
		//Sets up the outer walls and floor (background) of the game board.
		void BoardSetup ()
		{
			Debug.Log ("Creating board.");
			//~Z 16.01.31 | Clear out the previous one
			var levelHolder = GameObject.Find ("Level");
			if (levelHolder)
				for ( int i = levelHolder.transform.childCount; i <= 0; --i )
					GameObject.Destroy( levelHolder.transform.GetChild(i - 1) );
			//Instantiate Board and set boardHolder to its transform.
			boardHolder = new GameObject ("Board").transform;
			if (levelHolder)
				boardHolder.SetParent ( levelHolder.transform, true );
			
			//Loop along x axis, starting from -1 (to fill corner) with floor or outerwall edge tiles.
			for(int x = -1; x < columns + 1; x++)
			{
				//Loop along y axis, starting from -1 to place floor or outerwall tiles.
				for(int y = -1; y < rows + 1; y++)
				{
					//Choose a random tile from our array of floor tile prefabs and prepare to instantiate it.
					GameObject toInstantiate = floorTiles[Random.Range (0,floorTiles.Length)];
					
					//Check if we current position is at board edge, if so choose a random outer wall prefab from our array of outer wall tiles.
					if(x == -1 || x == columns || y == -1 || y == rows)
						toInstantiate = outerWallTiles [Random.Range (0, outerWallTiles.Length)];
					
					//Instantiate the GameObject instance using the prefab chosen for toInstantiate at the Vector3 corresponding to current grid position in loop, cast it to GameObject.
					GameObject instance =
						Instantiate (toInstantiate, new Vector3 (x, y, 0f), Quaternion.identity) as GameObject;
					
					//Set the parent of our newly instantiated object instance to boardHolder, this is just organizational to avoid cluttering hierarchy.
					instance.transform.SetParent (boardHolder);
				}//end.for(rows)
			}//end.for(columns)
		} //End.BoardSetup()
开发者ID:Zaelot,项目名称:Cultist-Meditation,代码行数:39,代码来源:BoardManager.cs

示例3: enumAttractFeather

    IEnumerator enumAttractFeather(Transform feather)
    {
        isMagneting = true;
        float deltaTime = 0.0f;
        float distanceToSlotSqrd = (myTransform.position - feather.position).sqrMagnitude;
        float minDistToCompSqrd = (manager.minDistToCompleteMagnet * manager.minDistToCompleteMagnet);

        Vector3 dirToSlot = (myTransform.position - feather.position).normalized;

        while( distanceToSlotSqrd > minDistToCompSqrd ) /// make custon normalize!!!!!!!!!!!!!!
        {
            deltaTime = Time.deltaTime;

            distanceToSlotSqrd = (myTransform.position - feather.position).sqrMagnitude; /// make custon normalize!!!!!!!!!!!!!!
            dirToSlot = (myTransform.position - feather.position).normalized; /// make custon normalize!!!!!!!!!!!!!!

            feather.position += dirToSlot * manager.magnetSpeed * deltaTime;

            feather.rotation = Quaternion.Lerp( feather.rotation, myTransform.rotation, manager.rotationMagnetSpeed * deltaTime );

            yield return new WaitForEndOfFrame();
        }

        feather.rotation = myTransform.rotation;
        feather.position = myTransform.position;
        feather.SetParent(myTransform);

        isEmpty = false;
    }
开发者ID:MashGames,项目名称:Flourny,代码行数:29,代码来源:FeatherSlot.cs

示例4: CreateUIImage

 //Alternate version that outputs the image transform
 public static Image CreateUIImage(Object obj, Vector2 pos, Transform parent, out Transform t)
 {
     GameObject g = Instantiate(obj, pos, Quaternion.identity) as GameObject;
     t = g.transform;
     t.SetParent(parent, false);
     return g.GetComponent<Image>();
 }
开发者ID:TheDarkVoid,项目名称:MikuSecret,代码行数:8,代码来源:Utils.cs

示例5: OpenWindow

 public void OpenWindow(string name)
 {
     windowOpen = true;
     currentWindowName = name;
     switch (name) {
     case "VideoSettings":
         newWindow = Instantiate(video);
         newWindow.SetParent(window, false);
         break;
     case "AudioSettings":
         newWindow = Instantiate(audio);
         newWindow.SetParent(window, false);
         break;
     case "GameplaySettings":
         newWindow = Instantiate(gameplay);
         newWindow.SetParent(window, false);
         break;
     case "AdvancedSettings":
         newWindow = Instantiate(advanced);
         newWindow.SetParent(window, false);
         break;
     case "ControlSettings":
         newWindow = Instantiate (controls);
         newWindow.SetParent (window, false);
         break;
     }
 }
开发者ID:MarbleGameDev,项目名称:2DPlatformer,代码行数:27,代码来源:OptionsManager.cs

示例6: Make

    void Make()
    {
        blocos = new List<Transform>();
        for(int i = 0; i < size; i++){
            for(int j = 0; j < size; j++){
                float y =
                    Mathf.PerlinNoise(
                        (float)i/size * width,
                        (float)j/size * width);

                Transform bloco;
                if(y >= neveY)
                    bloco = (Transform) Instantiate(prefabNeve);
                else if(y <= terraY)
                    bloco = (Transform) Instantiate(prefabTerra);
                else
                    bloco = (Transform) Instantiate(prefabGrama);

                bloco.SetParent(this.transform);
                bloco.position = new Vector3(i,y*height,j);
                blocos.Add(bloco);
            }
        }

        agua = (Transform)Instantiate(prefabAgua);
        agua.SetParent(this.transform);
        agua.localPosition = new Vector3(size/2f,aguaY,size/2f);
        agua.localScale = new Vector3(size,size,1);
    }
开发者ID:francasense,项目名称:okmijnuhv,代码行数:29,代码来源:Gerador.cs

示例7: OpenWindow

 public void OpenWindow(string name)
 {
     windowOpen = true;
     currentWindowName = name;
     switch (name) {
     case "MainMenu":
         newWindow = Instantiate(mainMenu);
         newWindow.SetParent(window, false);
         break;
     case "OptionsMenu":
         newWindow = Instantiate(optionsMenu);
         newWindow.SetParent(window, false);
         break;
     case "newGame":
         newWindow = Instantiate(newGame);
         newWindow.SetParent(window, false);
         break;
     case "PauseMenu":
         newWindow = Instantiate(pauseMenu);
         newWindow.SetParent(window, false);
         break;
     case "Inventory":
         newWindow = Instantiate (inventory);
         newWindow.SetParent(window, false);
         break;
     }
 }
开发者ID:MarbleGameDev,项目名称:2DPlatformer,代码行数:27,代码来源:MenuManager.cs

示例8: OpenCustomWindow

 public void OpenCustomWindow(Transform tempWindow)
 {
     windowOpen = true;
     currentWindowName = tempWindow.name;
     newWindow = Instantiate(tempWindow);
     newWindow.SetParent(window, false);
 }
开发者ID:MarbleGameDev,项目名称:2DPlatformer,代码行数:7,代码来源:MenuManager.cs

示例9: Init

  public void Init(Vector2 _sizeViewport, Level _level) {
    sizeViewport = _sizeViewport;
    level = _level;

    containerMap = new GameObject("Map").transform;
    containerMap.SetParent( transform );

    players = new List<Character>();
    Character c = new Character(10, 0, 49, 0, 0);
    c.name = "Fighter";
    c.actions.Add( new Action("attack") );

    c.health = c.maxHealth = 20;
    c.attack = 13;
    c.defense = 6;
    c.experience = 0;
    c.gold = 0;

    players.Add( c );

    theme = themePrefabs[0].GetComponent<MapTheme>();

    currentLevel = 0;
    NewLevel();
  }
开发者ID:birkoss,项目名称:roguelike,代码行数:25,代码来源:MapEngine.cs

示例10: BoardSetup

    void BoardSetup()
    {
        boardHolder = new GameObject("Board").transform;

        for (float y = MapPosition.y; y < (columns + 1 + MapPosition.y); y++)
        {
            for (float x = MapPosition.x; x < (rows + 1 + MapPosition.x); x++)
            {
                if (x == MapPosition.x || y == MapPosition.y || x == rows + MapPosition.x || y == columns + MapPosition.y)
                {
                    GameObject toInstantiate = GroundTile[1];
                    GameObject instance = Instantiate(toInstantiate, new Vector3(x * 0.64f - y * 0.64f, x * 0.32f + y * 0.32f, 0.01f * x + y * 0.01f), Quaternion.identity) as GameObject;
                    instance.transform.SetParent(boardHolder);
                }

                else
                {
                    GameObject toInstantiate = GroundTile[0];
                    GameObject instance = Instantiate(toInstantiate, new Vector3(x * 0.64f - y * 0.64f, x * 0.32f + y * 0.32f, 0.01f * x + y * 0.01f), Quaternion.identity) as GameObject;
                    instance.transform.SetParent(boardHolder);
                }
            }
        }

        MapPosition.x += ((rows + 1) * 0.64f - (columns + 2) * 0.64f);
        MapPosition.y += ((rows + 1) * 0.32f + (columns + 2) * 0.32f);

        boardHolder.SetParent(this.transform);
    }
开发者ID:hookSSi,项目名称:Prototype,代码行数:29,代码来源:BoardManager.cs

示例11: Awake

    void Awake()
    {
        agent = GetComponent<NavMeshAgent>();
        destinationMarker = transform.Find("moveToSphere");

        destinationMarker.SetParent(null);
    }
开发者ID:DanielQuick,项目名称:TanksAI,代码行数:7,代码来源:TankNavigation.cs

示例12: Start

    void Start()
    {
        leftBoundary = Instantiate(boundary, Vector3.zero, Quaternion.identity) as Transform;
        leftBoundary.SetParent(transform);
        leftBoundary.position -= new Vector3(battleFieldWidth / 2f, 0, 0);
        leftBoundary.localScale = new Vector3(1, battleFieldHeight, 1);

        rightBoundary = Instantiate(boundary, Vector3.zero, Quaternion.identity) as Transform;
        rightBoundary.SetParent(transform);
        rightBoundary.position += new Vector3(battleFieldWidth / 2f, 0, 0);
        rightBoundary.localScale = new Vector3(1, battleFieldHeight, 1);

        topBoundary = Instantiate(boundary, Vector3.zero, Quaternion.identity) as Transform;
        topBoundary.SetParent(transform);
        topBoundary.position += new Vector3(0, battleFieldHeight / 2f, 0);
        topBoundary.localScale = new Vector3(battleFieldWidth, 1, 1);

        bottomBoundary = Instantiate(boundary, Vector3.zero, Quaternion.identity) as Transform;
        bottomBoundary.SetParent(transform);
        bottomBoundary.position -= new Vector3(0, battleFieldHeight / 2f, 0);
        bottomBoundary.localScale = new Vector3(battleFieldWidth, 1, 1);

        leftBoundary.GetComponent<Boundary>().OnEnterBoundary += new OnTriggerEnterEventHandler(TeleportObjectToRightBoundary);
        rightBoundary.GetComponent<Boundary>().OnEnterBoundary += new OnTriggerEnterEventHandler(TeleportObjectToLeftBoundary);
        topBoundary.GetComponent<Boundary>().OnEnterBoundary += new OnTriggerEnterEventHandler(TeleportObjectToBottomBoundary);
        bottomBoundary.GetComponent<Boundary>().OnEnterBoundary += new OnTriggerEnterEventHandler(TeleportObjectToTopBoundary);
    }
开发者ID:Mojopon,项目名称:360Shooter,代码行数:27,代码来源:BoundariesController.cs

示例13: Start

    void Start()
    {
        tempEffect = Instantiate(effectPrefab);
        tempEffect.transform.position = transform.position;
        tempEffect.SetParent(gameObject.transform);

        deathTime = Time.time + lifetime;
    }
开发者ID:rdshack,项目名称:CProto,代码行数:8,代码来源:TornadoProjectile.cs

示例14: Initialize

    public void Initialize(Transform parent)
    {
        trans = transform;

        trans.SetParent (parent);
        trans.localPosition    = Vector3.zero;
        trans.localEulerAngles = Vector3.zero;
    }
开发者ID:n0mimono,项目名称:race-battle-simulation,代码行数:8,代码来源:Bullet.cs

示例15: Start

    void Start()
    {
        transform = GetComponent<Transform> ();
        player = GameObject.FindGameObjectWithTag ("Player").GetComponent<Transform> ();

        transform.Rotate (new Vector3 (0, 0, 78));
        transform.SetParent (player);
    }
开发者ID:tvance989,项目名称:wizard-game,代码行数:8,代码来源:ForcePush.cs


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