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 post has been wikified, any user with enough reputation can edit it.
avatar image
1
Question by Kitai · Mar 11, 2014 at 08:33 PM · renderingmaterialbuild-errorlinerendererray

LineRenderer missing in build

Hi, I have the problem that I found out few other people have had before me too but nobody seems to come up with actual solution or at least in every case those have been very different from each others.

So the thing is that I'm using LineRenderer to draw bullet lines and it works nicely in the editor but not at all in the build (I'm using win7, Unity4.3.0f4, 3d). Some people have solved this by lowering or raising their render settings, others by creating an extra material in the script but not actually even using it (http://answers.unity3d.com/questions/575167/linerenderer-not-showing-in-build.html) and for some people it has just suddenly started to work on its own. For me these won't seem to happen. Am I missing something? Help would be highly appreciated, I'm getting desperate :/

Here is the code that I'm using at the moment:

 `using UnityEngine;
 using System.Collections;
 
 public class Gun : MonoBehaviour {
 
     public LayerMask collisionMask;
     public Transform spawn;
     public GameObject gun;
     public float timeBetweenShots = 0.3f;
     public float damage = 1.0f;
         
     private float nextPossibleShootTime;
     private LineRenderer tracer;
 
     private float distance;
     private bool revealed;
 
     void Start(){
         tracer = GetComponent<LineRenderer>();
         revealed = false;
 
     }
 
     void Update(){
 
         if(Input.GetButtonDown("Fire2"))
             Shoot();
 
         distance = Vector3.Distance(GameObject.FindGameObjectWithTag("Prey").transform.position, GameObject.FindGameObjectWithTag("Predator").transform.position);
 
         if(distance<=30)
             revealed=true;
 
     }

     void Shoot(){
 
 
         if(CanShoot()){
             Ray ray = new Ray(spawn.position, -spawn.up);
             RaycastHit hit;
             Transform hitTransform;
             Vector3 hitPoint;
 
             hitTransform = FindClosestHitObject (ray, out hitPoint);
             float shotDistance = 25;
             
             if(Physics.Raycast(ray, out hit, shotDistance, collisionMask)){
                 shotDistance = hit.distance;
 
                 if(hitTransform != null)
                     Debug.Log("We hit: " + hitTransform.name);
 
                 if(hit.collider.GetComponent<Entity>()){
                     hit.collider.GetComponent<Entity>().TakeDamage(damage);
 
                 }
 
             }
             
             StartCoroutine("RenderTracer", ray.direction * shotDistance);
             
             nextPossibleShootTime = Time.time + timeBetweenShots;
         }
     }
 
     Transform FindClosestHitObject (Ray ray, out Vector3 hitPoint){
         
         RaycastHit[] hits = Physics.RaycastAll (ray);
         
         Transform closestHit = null;
         float distance = 0;
         hitPoint = Vector3.zero;
         
         foreach (RaycastHit hit in hits) {
             if(hit.transform != this.transform && (closestHit==null || hit.distance < distance)){
                 closestHit = hit.transform;
                 distance = hit.distance;
                 hitPoint = hit.point;
             }        
         }
         return closestHit;
         
     }
 
 
     private bool CanShoot(){
         bool canShoot = true;
 
         if((Time.time < nextPossibleShootTime) || (!revealed)){
             canShoot = false;
         }
 
         return canShoot;
     }
 
     IEnumerator RenderTracer(Vector3 hitPoint){
         tracer.enabled=true;
         tracer.SetPosition(0, spawn.position);
         tracer.SetPosition(1, spawn.position + hitPoint);
 
         yield return null;
         tracer.enabled = false;
     }
 
 }`

Most of this code is from Sebastian Lague's youtube Top Down Shooter tutorials, some from quill18creates youtube tutorials and some even my own :)

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
Best Answer

Answer by Kitai · Mar 13, 2014 at 07:33 AM

Ok, it seems to be working now. I created whole new script and did basically all the same things as above. I even copy&pasted some of the lines to the new script. And of, I deleted the LineRenderer component as well and readded it just to make sure there is nothing weird going on because of that.

Now that I think about it, there might have been some invisible symbols or letters in my script that I would had added by mistake. So maybe copy&paste to notepad and back to MonoDevelop (which at least I'm using) could work? I didn't try thou, just an idea.

Just in case someone wants to compare these two scripts, here is the one that I'm using now:

 using UnityEngine;
 using System.Collections;
 
 public class Shooting : MonoBehaviour {
     public LayerMask collisionMask;
     public Transform spawn;
     public float fireRate = 0.5f;
     public float damage = 25f;
     float cooldown = 0;
 
     private LineRenderer tracer;
     private float distance;
     private bool revealed;
 
     void Start(){
         tracer = GetComponent<LineRenderer>();
         revealed = false;
     }
     
     // Update is called once per frame
     void Update () {
         cooldown -= Time.deltaTime;
         distance = Vector3.Distance(GameObject.FindGameObjectWithTag("Prey").transform.position, GameObject.FindGameObjectWithTag("Predator").transform.position);
 
         if(distance <= 30)
             revealed=true;
 
         if ((Input.GetButtonDown ("Fire1") || Input.GetButtonDown ("Fire2")) && revealed) {
             Fire();        
         }
     }
     
     void Fire(){
         if (cooldown > 0) {
             return;
         }
 
         RaycastHit hit;
         Ray ray = new Ray (spawn.position, -spawn.up);
         Transform hitTransform;
         Vector3 hitPoint;
         float shotDistance = 25;
         
         hitTransform = FindClosestHitObject (ray, out hitPoint);
 
         if(Physics.Raycast(ray, out hit, shotDistance, collisionMask)){
             shotDistance = hit.distance;
             
             if(hitTransform != null)
                 Debug.Log("We hit: " + hitTransform.name);
             
             if(hit.collider.GetComponent<Entity>()){
                 hit.collider.GetComponent<Entity>().TakeDamage(damage);
                 
             }
             
         }
 
         StartCoroutine("RenderTracer", ray.direction * shotDistance);
 
         cooldown = fireRate;
         
     }
     
     Transform FindClosestHitObject (Ray ray, out Vector3 hitPoint){
         
         RaycastHit[] hits = Physics.RaycastAll (ray);
         
         Transform closestHit = null;
         float distance = 0;
         hitPoint = Vector3.zero;
         
         foreach (RaycastHit hit in hits) {
             if(hit.transform != this.transform && (closestHit==null || hit.distance < distance)){
                 closestHit = hit.transform;
                 distance = hit.distance;
                 hitPoint = hit.point;
             }        
         }
         return closestHit;
         
     }
 
     IEnumerator RenderTracer(Vector3 hitPoint){
         tracer.enabled=true;
         tracer.SetPosition(0, spawn.position);
         tracer.SetPosition(1, spawn.position + hitPoint);
         
         yield return null;
         tracer.enabled = false;
     }
     
 }
Comment
Add comment · Show 2 · 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 getyour411 · Mar 13, 2014 at 07:40 AM 0
Share

BTW - You should be able to accept your solution, tick the 'Accept Answer' icon below the thumbs (not the vote up/down)

avatar image Kitai · Mar 13, 2014 at 09:14 AM 0
Share

Oh, look at that. I though that without enough karma I couldn't do even that. Thanks!

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

20 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

Related Questions

Line renderer jagged display issue 0 Answers

How do I render the inside of a transparent model (a glass jar)? 1 Answer

Player position changes lighting. 0 Answers

URP material set texture scale 0 Answers

overlaying object problem 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