Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 /
This question was closed Nov 20, 2021 at 06:59 PM by Bmarlyman21 for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by Bmarlyman21 · Dec 27, 2013 at 04:44 PM · muzzleflash

Muzzle Flash

I have a texture of a muzzle flash and i'm going to apply it to an object, the thing i'm wondering is how do i make the object's rendering enable and disable rapidly while the mouse is held down.

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

  • Sort: 
avatar image
1
Best Answer

Answer by robertbu · Dec 28, 2013 at 11:19 PM

Here is one solution. I imagine you want to start with the renderer for the flash graphic disabled:

 #pragma strict
 
 var speed = 20.0;
 
 function Update() {
     if (Input.GetMouseButton(0)) {
         renderer.enabled = (Mathf.PingPong(Time.time * speed, 1.0) < 0.5);
     }
     if (Input.GetMouseButtonUp(0)) {
         renderer.enabled = false;
     }
 }
Comment
Add comment · Show 5 · 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 Bmarlyman21 · Dec 29, 2013 at 02:14 PM 0
Share

hmm, i never thought to do it that way. thanks

avatar image Bmarlyman21 · Dec 29, 2013 at 07:36 PM 0
Share

ok so the way i asked for sucks, you gave me what i asked for and thanks, but i think i should make it so that ins$$anonymous$$d of turning it on and off it switches between 5 or 6 different texture every certain amount of time.

avatar image robertbu · Dec 29, 2013 at 08:02 PM 0
Share

Here is a bit of code that uses a set of images. You need to initialize the array in the Inspector.

 #pragma strict
 
 var textures : Texture[];
 var fps = 10.0;
  
 function Update () {
     if (Input.Get$$anonymous$$ouseButton(0)) {
         renderer.enabled = true;
         var i = (Time.time * fps) % textures.Length;
         renderer.material.mainTexture = textures[i];
     }
     else {
         renderer.enabled = false;
     }
 }
avatar image robertbu · Dec 29, 2013 at 08:06 PM 0
Share

Here is a different script that displays a random texture rather than displays textures in order:

 #pragma strict
 
 var textures : Texture[];
 
 function Start() {
     InvokeRepeating("ShowTextures", 0.0, 0.1);
 }
  
 function ShowTextures() {
     if (Input.Get$$anonymous$$ouseButton(0)) {
         renderer.enabled = true;
         renderer.material.mainTexture = textures[Random.Range(0, textures.Length)];
     }
     else {
         renderer.enabled = false;
     }
 }
avatar image Bmarlyman21 · Dec 29, 2013 at 10:17 PM 0
Share

ok thanks man

Follow this Question

Answers Answers and Comments

18 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

Related Questions

Instantiating Muzzle Flash 1 Answer

How do i put lights with muzzleflash? 1 Answer

Muzzleflash Question 3 Answers

Why the particle system don't play? 2 Answers

How to make and use a muzzleflash 1 Answer


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