instantiate offset unity

 // C#
 
 public GameObject objectPrefab;
 
 // ...
 
 // Example using Start function
 void Start()
 {
     // Use the prefab's position and rotation
     Instantiate(objectPrefab, objectPrefab.position, objectPrefab.rotation);
     
     // Override the prefab's coordinates (with zero-coordinates)
     Instantiate(objectPrefab, Vector3.zero, Quaternion.identity);
     
     // Provide an offset to the stored values
     Instantiate(objectPrefab, objectPrefab.position + (Vector3.up * 1.63f), objectPrefab.rotation * Quaternion.AngleAxis(30.0f, Vector3.up));
 }

3.33
3
Phoenix Logan 186120 points

                                     if ( structureIndex == 0 )
                    {    
                        var offset : Vector3 = new Vector3(0.5f, 0.5f, 0);
                        Instantiate(allStructures[structureIndex], lastHitObj.transform.position + offset, Quaternion.identity );                    
                    }

3.33 (3 Votes)
0
Are there any code examples left?
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source