Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
avatar image
0
Question by givememycookies · Mar 11, 2019 at 01:24 PM · instantiateprefabprojectilearrow

Im trying to get an arrow to shoot with mouse click but the arrow doesn't show up even though on the hierarchy menu it's showing up.

Hi,

Im trying to get an arrow to shoot with mouse click but the arrow doesn't show up even though on the hierarchy menu it's showing up as projectile clone.

Please help #dying alt text using System.Collections; using System.Collections.Generic; using UnityEngine;

 public class ProjectileShooter : MonoBehaviour {
 
     GameObject prefab; 
 
     
     void Start () {
 
         //calling out the arrow prefab
         prefab = Resources.Load("projectile") as GameObject;
     }
     
     
     void Update () {
 
         //if player left clicks mouse it shoots
         if (Input.GetMouseButtonDown(0))
         {
             //new variable for the projectile | Instantiate: to create an instance of an object
             GameObject projectile = Instantiate(prefab) as GameObject;
 
             //projectile is from both the players and camera's positions + its *2 forward so its not inside characters head
             projectile.transform.position = transform.position + Camera.main.transform.forward * 2;
 
             //make it move at the right speed
             Rigidbody rb = projectile.GetComponent<Rigidbody>();
             //take where were looking + speed
             rb.velocity = Camera.main.transform.forward * 40;
         }
     }
 }


capture.png (8.9 kB)
Comment
Add comment · Show 4
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 xxmariofer · Mar 11, 2019 at 01:54 PM 0
Share

can you share the inspector of the cloned objects?

avatar image givememycookies xxmariofer · Mar 11, 2019 at 02:25 PM 0
Share

Hi,

Its showing up now that its bigger buuuuuuut it appears and disappears it doesn't actually go forwards and its really fast.

alt text

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class Arrow : $$anonymous$$onoBehaviour {
 
     private GameObject arrowPrefab;
 
     // Use this for initialization
     private void Start () {
 
         arrowPrefab = Resources.Load("projectile") as GameObject;
         
     }
     
     // Update is called once per frame
     void Update () {
         if(Input.Get$$anonymous$$ouseButtonDown(0))
         {
             GameObject newArrow = Instantiate(arrowPrefab) as GameObject;
             newArrow.transform.position = transform.position;
 
             Rigidbody rb2 = newArrow.GetComponent<Rigidbody>();
             rb2.velocity = Camera.main.transform.forward * 30;
         }
         
     }
 }


 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class ArrowPt2 : $$anonymous$$onoBehaviour {
 
     Rigidbody rb2; 
 
     // Use this for initialization
     void Start () {
 
         rb2 = GetComponent<Rigidbody>(); 
         
     }
     
     // Update is called once per frame
     void Update () {
 
         transform.rotation = Quaternion.LookRotation(rb2.velocity);
         
     }
 }
 


arrow.png (46.6 kB)
avatar image xxmariofer givememycookies · Mar 11, 2019 at 03:17 PM 0
Share

well thats because 30 velocity is so much, lowering the speed didnt help?

avatar image Tsaras · Mar 11, 2019 at 05:35 PM 0
Share

You can pause the game right after you shoot the projectile, go to scene view, select the projectile in the hierarchy and press F to zoom in on it to see where it is etc.

0 Replies

· Add your reply
  • Sort: 

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

145 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Change a prefab sprite using Random.range instantiate in a script 3 Answers

How to instantiate a projectile only from the weapon prefab of the firing player? 1 Answer

Don't render prefab until onCollision - related, parent prefab.. 0 Answers

Instantiated Object being auto-deleted 0 Answers

Issue Instantiating prefab in C# 0 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