• 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 /
This question was closed Apr 22, 2016 at 09:07 PM by Alexander42 for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by Alexander42 · Apr 22, 2016 at 06:55 PM · 2dinstantiateprefabinput

Trying to get a 2d prefab without rigidbody to instantiate on button press, "the variable T_Bullet has not been assigned."

Full Code:

   using UnityEngine;
     using System.Collections;
     
 public class player_script : MonoBehaviour {
     public float speed = 8f;
     public float countdown = 3.0f;
     private bool m_Fired;
     public GameObject T_Bullet;
     // Use this for initialization
 
     void Start () {
     
     }
     
     // Update is called once per frame
     void Update () {
 
         if (Input.GetButton("Fire1"))
         { transform.Translate(Vector2.up * Time.deltaTime ); }
 
         if (Input.GetButton("Fire2"))
         { transform.Translate(Vector2.down * Time.deltaTime ); }
 
         if (Input.GetButton("Jump"))
         { Fire(); }
     }
 
     private void Fire()
     {
         Instantiate(T_Bullet,Vector2.right, Quaternion.identity);
 
     }
 }


Trying to get a bullet prefab to spawn when the spacebar is pressed, but the Console gives me that error message. Most of the other answers for this topic involve 2d Rigidbodies, which I have no reason to use for the sort of game I am making

Comment
Add comment · Show 1
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 KidRigger · Apr 22, 2016 at 07:17 PM 1
Share

I believe you have already added the prefab into the inspector, why not add a kinematic rigidbody2D? It won't have gravity or be affected by any forces

0 Replies

  • Sort: 

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

89 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

Related Questions

Size of instantiated clone is different from prefab 0 Answers

Newly Instantiated Prefabs Not Changing Colour 1 Answer

How do I fix 2d Grid Instantiating? 1 Answer

how can I instantiate bullet prefabs continuously while holding the left mouse button? ,how can I instantiate bullet prefabs continuously while holding the left click button? 0 Answers

Spawning Prefab not working correctly 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