Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

[Script Attached] Why won't it place and rotate?

Discussion in 'Scripting' started by Xatu1992, Mar 24, 2015.

  1. Xatu1992

    Xatu1992

    Joined:
    Mar 22, 2015
    Posts:
    13
    Basically a place script where my player will place a wall onto a build zone. It copies the rotation when its the buildzone is the same direction as my prefab but if I rotate my buildzone 90 and try place the block on top again it does rotate it just stays on 0.

    Code (JavaScript):
    1. #pragma strict
    2. var prefab : Transform;
    3.  
    4. function Start () {
    5.    
    6. }
    7.  
    8.  
    9. function Update(){
    10.      if(Input.GetMouseButtonUp(0)){
    11.          var ray : Ray = GetComponent.<Camera>().main.ScreenPointToRay (Input.mousePosition);
    12.          var hit : RaycastHit;
    13.          if (Physics.Raycast(ray, hit,Mathf.Infinity)){
    14.              if(hit.collider.tag == "BuildZone" && "Wood"){
    15.                  var placePos : Vector3 = hit.point;
    16.                  placePos.y += 1;
    17.                  placePos.x = Mathf.Round(placePos.x);
    18.                  placePos.z = Mathf.Round(placePos.z);
    19.                 // Instantiate (prefab, placePos, Quaternion.identity);
    20.                 Instantiate(prefab, placePos, Quaternion.identity);
    21.                
    22.              
    23.              }
    24.          }
    25.   } }
    26.  
    I can post a screenshot if you don't understand.
    Anyone know whats up?
     
  2. blizzy

    blizzy

    Joined:
    Apr 27, 2014
    Posts:
    775
    Please do - the more info the better.

    Also, I don't see any rotation? Quaternion.identity always stays the same.
     
  3. Xatu1992

    Xatu1992

    Joined:
    Mar 22, 2015
    Posts:
    13


    if you see the second one doesn't copy the transform properly