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 Irin · Nov 16, 2015 at 12:46 AM · c#programmingdecal

Yet Another Bullet Decal Problem

Ive ran through two pages, on this problem, but the solution is the decal system that is 95$ or not being sold anymore. Ive cobbled some code together but the decals are not being painted so to speak. Note i am using particles for the decals rather than textures. So, why would my particle bullet decals not be painted.

 public class SCAR : MonoBehaviour 
 {
     Vector3 point;
 
     public Rigidbody b_556mm;//the rigid body containter for an object for the bullet
     public Transform Spawn;//this is the location the bullet will spwan from
     public float speed = 5.0f;//bullets speed
     public int damage = 75;//damage by the weapon
 
     public GameObject decalHitWall;//the particle to be used as bullet decal
 
        RaycastHit hit = new RaycastHit();
     Ray hitray = new Ray();
 
     public float baseFOV;
 
     float fireRate = 0.15f;
     float lastShot = -10.0f;
 
     public int bullets = 30;
     int bulletsDummy;
     public int mag = 3;
 
     public Font Tinker;//font used for the GUI render
 
     // Use this for initialization
     void Start () 
     {
         baseFOV = Camera.main.fieldOfView;
     }
 
 
     // Update is called once per frame
     void Update () 
     {
         bulletsDummy = bullets;
         hitray = Camera.main.ViewportPointToRay(new Vector3(0.5f, 0.5f, 0));
         //Fire Mechanisms.
             if(Input.GetKey(KeyCode.Mouse0))
             {
                 if(bullets > 0 && mag > 0)
                 {
                     if(Time.time > fireRate + lastShot)
                     {
 
                         if (Physics.Raycast(hitray, out hit, 1000.0f))
                         {
                             point = hit.point;
                             Spawn.transform.LookAt(point);
                             
                             //Bullet prefabs go here
                             GameObject decalClone = (GameObject)Instantiate(decalHitWall, hit.point, Quaternion.LookRotation(Vector3.up, hit.normal));
                             Destroy(decalClone.gameObject, 30);
                             
                             
                         Debug.DrawRay(hitray.origin, hitray.direction, Color.blue, 100, true);
 
                             Health enemyHealth = hit.transform.GetComponent<Health>();
                                 if(enemyHealth != null)
                                 {
                                     enemyHealth.Damage(damage);
                                 }
                                 print (hit.transform.name);    // logs it into the console
                         
                         }
 
                         Rigidbody instance = (Rigidbody)Instantiate(b_556mm, Spawn.position, Spawn.rotation);
                         instance.AddForce(transform.forward * speed);
                 
                         GetComponent<AudioSource>().Play();
                 
                         lastShot = Time.time;
 
                         Destroy(instance.gameObject, 1);//destroy the rigidboy to save on memmory after a second.
 
                         bullets--;
                     //print("bullets left: " + bullets);
 
                     }//end time if
                     
                 //    print(Value(bullets, mag));
                     
                     
                     if(bullets == 0)
                     {
                             
                                 mag--;
                                 //print("mag left: " + mag);
                                 bullets = 30;
                             
                             
 
                     }
                         
                 }//end bullets nad mag if
 
         }//end input if
     
 
         //Zoom Mechanism
         if(Input.GetButton ("Fire2"))
         {
             Camera.main.fieldOfView = 25;
 
         }
         else
         {
             Camera.main.fieldOfView = baseFOV;
         }
 
     }
 
     void OnGUI()
     {
 
         GUIStyle TinkerFont = new GUIStyle();
         TinkerFont.font = Tinker;//this works, changes the hud to Tinker Font.
         TinkerFont.fontSize = 24;
         TinkerFont.normal.textColor = Color.red;
 
         GUI.Label(new Rect(900,500, 75,35),Value(bullets, mag), TinkerFont);
     }
     public string Value(int a, int b)
     {    
         string total;
         return total = bullets + " / " + mag;
     }
          
 }//end class
 
 
 
 

Comment
Add comment · Show 3
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 Cherno · Nov 16, 2015 at 09:35 AM 0
Share

Is the clone of the particle prefab instantiated correctly? If it's there, but not visible, then it's a problem with the settings of the ParticleSystem component.

avatar image Irin Cherno · Nov 17, 2015 at 01:10 AM 0
Share

I believe so. Granted i took that line and adjusted it a bit. I have no particle system component attached. I am just calling the particle as a game object. I dont think that i a problem. Ive done it before.

avatar image Cherno Irin · Nov 17, 2015 at 10:06 AM 0
Share

Just to be clear. The Prefab "decalHitWall" has a ParticleObject component on it and if dragged into the scene manually, it will play correctly and show the bullet mark particle, right?

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

33 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

Related Questions

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

Jagged Array 2 Answers

Avatar constructor returns null 1 Answer

Use local instantiated variable outside of scope 2 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