Search Unity

  1. Unity 2019.2 is now released.
    Dismiss Notice

Help, I have problems with instantiating prefab

Discussion in 'Scripting' started by BlendCraft, Aug 9, 2016.

  1. BlendCraft

    BlendCraft

    Joined:
    Nov 2, 2014
    Posts:
    274
    I googled this code and it is working for other people but not me.

    Error report:


    Assets/shell_eject.cs(16,18): error CS1502: The best overloaded method match for `UnityEngine.Object.Instantiate(UnityEngine.Object, UnityEngine.Vector3, UnityEngine.Quaternion)' has some invalid arguments



    Code (csharp):
    1.  
    2. using UnityEngine;
    3. using System.Collections;
    4.  
    5. public class shell_eject : MonoBehaviour {
    6. public GameObject shell;
    7.     // Use this for initialization
    8.     void Start () {
    9.  
    10.     }
    11.  
    12.     // Update is called once per frame
    13.     void Update () {
    14.     if (Input.GetButtonDown ("Trig1")) {
    15.      
    16.             GameObject shellc;
    17.     shellc = Instantiate(shell, transform.position, transform.rotation, Quaternion.identity) as GameObject;
    18.  
    19.     }
    20. }
    21. }
    22.  
    23.  
    24.  
    Your help matters...

    This is a spent cartridge ejection script for rifles in my shooter game project.
     
  2. DanielQuick

    DanielQuick

    Joined:
    Dec 31, 2010
    Posts:
    3,137
    Instantiate takes 3 parameters. You are giving 4.
     
  3. LTK

    LTK

    Joined:
    Jul 16, 2015
    Posts:
    22
    BlendCraft likes this.
  4. BlendCraft

    BlendCraft

    Joined:
    Nov 2, 2014
    Posts:
    274
    So that is what the error meant. Thnx for the tip guys