How to make an object parent to a Camera through code?
I'm trying to make an object in which I am able to click, and it will become a parent to my camera. I thought I knew how to do this, however, when I click it, it grows instead? Can someone explain why, and how I would go about fixing it?
Here's my code
 void Update()
     {
         Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
         RaycastHit hit;
         if (Physics.Raycast(ray, out hit) && hit.collider.gameObject.tag == "Brick")
         {
             Renderer rend = gameObject.GetComponent<Renderer>();
             rend.material = texture;
             if (Input.GetMouseButtonDown(0) && holding == false)
             {
                 transform.parent = Camera.main.transform;
                 holding = true;
             }
         }
         else
         {
             Renderer rend = gameObject.GetComponent<Renderer>();
             rend.material = normal;
         }
         if(Input.GetMouseButtonDown(0) && holding == true)
         {
             gameObject.transform.parent = null;
             holding = false;
         }
     }
               Comment
              
 
               
              Your answer
 
 
             Follow this Question
Related Questions
Toogle Parent to Camera Function - Google Cardboard 0 Answers
Rotate camera when colliding 0 Answers
Camera Rotation Around Player 1 Answer
uNet hitboxes and movement. 0 Answers
When playing builded version of game the cameras only captures part of scene. 0 Answers
 koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                