Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
0
Question by snon200 · Mar 25, 2016 at 05:53 PM · unity 5javascriptinstantiateparentingbullethole

bullet holes parenting

hi, i want to parent my bullet holes to the object they hit so if the object moves the bullet holes move with it and dont get stuck in the air. here's my code:

 #pragma strict
 
 var bulletTex : GameObject[]; // creates an array to use random textures of bullet holes
 var clicked = false;
 var clicked2 = false;
 var pauseMenu = false;
 
 function Start () {
 
 }
 
 function Update () {
  
     var fwd = transform.TransformDirection(Vector3.forward); //casts our raycast in the forward direction
  
     var hit : RaycastHit;
  
     Debug.DrawRay(transform.position, fwd * 100, Color.green); //drays our raycast and gives it a green color and a length of 10 meters
 
     if((Input.GetKeyDown("2"))|(raycast.BulletsLeft == 0)){
         clicked = true;
     }
 
     if((Input.GetKeyDown("1"))&(raycast.BulletsLeft != 0)){
         clicked = false;
     }
 
     if(Input.GetKeyDown("escape")){
             if(pauseMenu == true){
                 pauseMenu = false;
                 if(clicked2 == false){
                     clicked = false;
                 } else if(clicked2 == true){
                     clicked = true;
                 }
             } else if(pauseMenu == false) {
                 pauseMenu = true;
                 if(clicked == true){
                     clicked2 = true;
                 } else if(clicked == false){
                     clicked = true;
                     clicked2 = false;
                 }
             }
             }
     
     if(!clicked){
         if(Input.GetButton ("Fire1") && Physics.Raycast(transform.position, fwd, hit, 100)){
             Instantiate(bulletTex[Random.Range(0,1)], hit.point+0.001*hit.normal, Quaternion.FromToRotation(Vector3.up, hit.normal)); 
         }
     }
 
     if(clicked){
         if(Input.GetButton ("Fire1") && Physics.Raycast(transform.position, fwd, hit, 100)){
             Instantiate(bulletTex[Random.Range(1,2)], hit.point, Quaternion.FromToRotation(Vector3.up, hit.normal));
         }
     }
     }
Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by Happy-Zomby · Mar 25, 2016 at 06:12 PM

Hi, you can parent it to the hit object by doing something like this:

 if(Input.GetButton ("Fire1") && Physics.Raycast(transform.position, fwd, hit, 100))
     {
     var tempBullet : Instantiate(bulletTex[Random.Range(1,2)], hit.point, Quaternion.FromToRotation(Vector3.up, hit.normal));
     tempBullet.transform.parent = hit.transform;   
      }

Hope that helps,

Comment
Add comment · Show 6 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image snon200 · Apr 04, 2016 at 02:57 PM 0
Share

thanks but it doesnt work :( i get errors

avatar image Happy-Zomby snon200 · Apr 04, 2016 at 04:34 PM 0
Share

Can you post your errors?

avatar image snon200 Happy-Zomby · Apr 04, 2016 at 04:52 PM 0
Share

Assets/BulletHoles.js(49,41): UCE0001: ';' expected. Insert a semicolon at the end.

Assets/BulletHoles.js(49,70): BCE0044: expecting ), found ','.

Assets/BulletHoles.js(49,71): UCE0001: ';' expected. Insert a semicolon at the end.

Assets/BulletHoles.js(49,81): BCE0043: Unexpected token: ,.

Assets/BulletHoles.js(49,82): UCE0001: ';' expected. Insert a semicolon at the end.

Assets/BulletHoles.js(49,132): BCE0043: Unexpected token: ).

Show more comments
avatar image snon200 · Apr 05, 2016 at 11:10 AM 0
Share

thanks but it doesnt work, now i cant see the bullet holes at all..

avatar image hossenshovon1 · Jun 22, 2021 at 08:31 PM 1
Share

@Happy-Zomby Oh You just Did it, Thanks a lot to you. It Works fine for me. You are awesome

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Can't access specific element in multidimensional array (JavaScript) 1 Answer

how to Import unity3d project to an existed ios native app 0 Answers

Expecting EOF, found public 1 Answer

Why can't I move player's game piece on 2nd turn? 0 Answers

SPACE SHOOTER SHOOTING SHOTS TUTORIAL HELP (UNITY 5 C#) 3 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges