Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

i dont get this code, please help

Discussion in 'Scripting' started by SQUARE-BADGER, Aug 19, 2016.

  1. SQUARE-BADGER

    SQUARE-BADGER

    Joined:
    Jul 15, 2015
    Posts:
    13
    Type `Bullet' does not contain a definition for #speed' and no extension method #speed' of type #Bullet' could be found #are you missing a using directive or an assembly reference?

    what is the problem???

    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class Gun : MonoBehaviour {
    5.     public GameObject bullet;
    6.     public float speed;
    7.  
    8.     // Use this for initialization
    9.     void Start () {
    10.         bullet.GetComponent<Bullet>().speed = speed;
    11.    
    12.     }
    13.    
    14.     // Update is called once per frame
    15.     void Update () {
    16.    
    17.     }
    18.  
    19.     public void Shoot()
    20.     {
    21.         Instantiate(bullet, transform.position, transform.rotation);
    22.     }
    23. }
    24.  
     
  2. LeftyRighty

    LeftyRighty

    Joined:
    Nov 2, 2012
    Posts:
    5,148
    your bullet script doesn't have a public variable called "speed"...
     
  3. RavenOfCode

    RavenOfCode

    Joined:
    Apr 5, 2015
    Posts:
    869
    This.