Search Unity

  1. Improved Prefab workflow (includes Nested Prefabs!), 2D isometric Tilemap and more! Get the 2018.3 Beta now.
    Dismiss Notice
  2. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  3. Let us know a bit about your interests, and if you'd like to become more directly involved. Take our survey!
    Dismiss Notice
  4. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    Dismiss Notice
  5. Want to see the most recent patch releases? Take a peek at the patch release page.
    Dismiss Notice

Trying to reduce the yellow warnings in project

Discussion in 'Scripting' started by tawdry, May 16, 2018.

  1. tawdry

    tawdry

    Joined:
    Sep 3, 2014
    Posts:
    1,124
    Hi
    So i have a couple hundred yellow warning from assets iv downloaded mostly particle systems so trying to cut down on them but can't figure out why this code gives the following warning


    Assets/Standard Assets/Effects/ImageEffects/FT_Infinity_lite/Scenes/Data/Scripts/SpawnProjectile.cs(50,15): warning CS0219: The variable `projectile' is assigned but its value is never used


    Error points to the last line how can i rewrite it to have the yellow error msg go bye bye.


    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using UnityEngine.UI;
    5.  
    6. public class SpawnProjectile : MonoBehaviour {
    7.  
    8.     public Camera mainCam;
    9.     public Transform spawn;
    10.     public GameObject[] effects;
    11.     private int count = 0;
    12.     public Text text;
    13.  
    14.     // Use this for initialization
    15.     void Start () {
    16.         text.text = effects [count].name;
    17.     }
    18.    
    19.     // Update is called once per frame
    20.     void Update () {
    21.         //Player Look at Mouse Position
    22.         Ray ray = mainCam.ScreenPointToRay(Input.mousePosition);
    23.         Plane ground = new Plane (Vector3.up, Vector3.zero);
    24.         float rayDistance;
    25.         if (ground.Raycast (ray, out rayDistance)) {
    26.             Vector3 point = ray.GetPoint (rayDistance);
    27.             Vector3 correctPoint = new Vector3 (point.x, transform.position.y, point.z);
    28.             transform.LookAt (correctPoint);
    29.         }
    30.         if (Input.GetKeyDown (KeyCode.RightArrow)) {
    31.             if (count >= effects.Length -1) {
    32.                 count = 0;
    33.             } else {
    34.                 count++;
    35.             }
    36.             text.text = effects [count].name;
    37.         }
    38.  
    39.         if (Input.GetKeyDown (KeyCode.LeftArrow)) {
    40.             if (count <= 0) {
    41.                 count = effects.Length -1;
    42.             } else {
    43.                 count--;
    44.             }
    45.             text.text = effects [count].name;
    46.         }      
    47.  
    48.         //Shoot
    49.         if(Input.GetMouseButtonDown(0)){
    50.             GameObject projectile = Instantiate (effects[count], spawn.position, spawn.rotation);
    51.         }
    52.     }
    Thx
     
  2. GroZZleR

    GroZZleR

    Joined:
    Feb 1, 2015
    Posts:
    1,720
    Error is pretty clear: you assign the value but don't do anything with it, making the assignment pointless.

    Code (csharp):
    1.  
    2. GameObject projectile = Instantiate (effects[count], spawn.position, spawn.rotation);
    3.  
    can become

    Code (csharp):
    1.  
    2. Instantiate (effects[count], spawn.position, spawn.rotation);
    3.  
     
  3. tawdry

    tawdry

    Joined:
    Sep 3, 2014
    Posts:
    1,124
    Ah ok thx.