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 /
avatar image
0
Question by yyamiyyugi · Jul 30, 2013 at 07:17 PM ·

No Overload for method 'Instantiate' takes '7' arguments?

Hello, First of all I want to apoligize if this is a stupid question.

I am fairly new to unity and C# in general but I was (almost) able to get together a health script, My issue is respawning, I am attempting to use Instantiate to clone the player and respawn him at the spawn point, here is that bit of code

 Instantiate("Player", 23.21657, 3.257863, -0.6684538,0, 0, 0);

But when I go to build it I get the error in the title, I already have the 7 args though?

Anyway, here is the full code, Thanks in advance for any help

 enter code here 
     public class Health : MonoBehaviour {
     
     public float maxHealth = 100.0f ;
     public float curHealth = 100f ;
      
      
     void Start(){
        curHealth = maxHealth ;
             var Player = gameObject.CompareTag("Player");
         
     }
      
     void Update(){
             bool Player = gameObject.CompareTag("Player");
        if(curHealth < 0)
                 curHealth = 0;
             
        if(curHealth == 0)
                 
         Instantiate("Player", 23.21657, 3.257863, -0.6684538,0, 0, 0);
      
        if(curHealth > maxHealth)
           curHealth = maxHealth ;
     }
     
      
     void OnGUI(){
           GUI.Label(new Rect(100,100,100,100), curHealth + "/" + maxHealth);
        
     }
      
     
      
     void ApplyDamage(float damage){
        curHealth -= damage ;
     }
         
            void OnTriggerEnter(Collider other) {
         if(other.gameObject.CompareTag("Zombie")){
                 ApplyDamage(10);
             }
     }}
     
 
Comment
Add comment · Show 3
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 hoy_smallfry · Jul 30, 2013 at 07:23 PM 0
Share

The error is saying that there are no versions of Instantiate that can take 7 arguments. There is only one version of Instantiate, and it takes only 3 arguments: an original Object, a position, and an orientation.

avatar image hoy_smallfry · Jul 30, 2013 at 07:28 PM 0
Share

Instantiating is used for cloning an object. You can't clone the player from just the name alone. You have to use the original, but I don't believe that works if you have destroyed the original.

Ins$$anonymous$$d, try looking into prefabs. If you create a prefab out of the player object and then create a new instance of the prefab, this will give you the effect you want.

  • Creating a prefab

  • Instantiating Prefabs in a script

avatar image Jonathon82931 · Jul 30, 2013 at 09:38 PM 0
Share

thanks this helps me in something I am working on today

4 Replies

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by Seizure · Jul 30, 2013 at 07:27 PM

Just drop your player prefab on Player in Unity Editor and use this code:

 using UnityEngine;
 using System.Collections;
 
  public class Health : MonoBehaviour 
 {
  
     public float maxHealth = 100.0f ;
     public float curHealth = 100f ;
     public GameObject Player;
  
  
     void Start(){
        curHealth = maxHealth ; 
     }
  
     void Update(){
         
        if(curHealth < 0)
           curHealth = 0;
  
        if(curHealth == 0)
        Instantiate(Player, new Vector3 (23.21657f, 3.257863f, -0.6684538f), Quaternion.identity);
  
        if(curHealth > maxHealth)
           curHealth = maxHealth ;
     }
  
  
     void OnGUI(){
          GUI.Label(new Rect(100,100,100,100), curHealth + "/" + maxHealth);
  
     }
  
  
  
     void ApplyDamage(float damage){
        curHealth -= damage ;
     }
  
           void OnTriggerEnter(Collider other) {
        if(other.gameObject.CompareTag("Zombie")){
           ApplyDamage(10);
          }
     }
 }
Comment
Add comment · Show 1 · 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 yyamiyyugi · Jul 30, 2013 at 09:31 PM 0
Share

Thanks so much It worked like a charm!

avatar image
-1

Answer by sdadadwqR · Jun 02, 2015 at 10:49 PM

zxzxzxzxzxxz poo is nutritious

add pampamsam on ROBLOX

Comment
Add comment · 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
0

Answer by jacobschellenberg · Jul 30, 2013 at 07:23 PM

Instantiate takes a GameObject, Vector3 Position and Rotation.

For example:

 public GameObject playerPrefab;
 
 void Start(){
 
     Instantiate(playerPrefab, new Vector3(0, 0, 0), Quaternion.Identity);
 
 }

Don't forget to assign the prefab to the public variable in the Inspector.

So essentially you could end up with this:

 using UnityEngine;
 using System.Collections;
  
  public class Health : MonoBehaviour 
 {
  
     public float maxHealth = 100.0f ;
     public float curHealth = 100f ;
     public GameObject playerPrefab;
  
  
     void Start(){
        curHealth = maxHealth ; 
     }
  
     void Update(){
  
        if(curHealth < 0)
           curHealth = 0;
  
        if(curHealth == 0)
        Instantiate(playerPrefab, new Vector3 (23.21657f, 3.257863f, -0.6684538f), Quaternion.identity);
  
        if(curHealth > maxHealth)
           curHealth = maxHealth ;
     }
  
  
     void OnGUI(){
          GUI.Label(new Rect(100,100,100,100), curHealth + "/" + maxHealth);
  
     }
  
  
  
     void ApplyDamage(float damage){
        curHealth -= damage ;
     }
  
           void OnTriggerEnter(Collider other) {
        if(other.gameObject.CompareTag("Zombie")){
           ApplyDamage(10);
          }
     }
 }

Hope this helps :)

Comment
Add comment · 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
0

Answer by Bunny83 · Jul 30, 2013 at 07:30 PM

Well, pretty much what the error is telling you. There are multiple versions of Instantiate but non takes 7 arguments, only 3. You want something like:

 Instantiate(player, new Vector3(23.21657f, 3.257863f, -0.6684538f), Quaternion.Euler(0f,0f,0f));

where player should be a reference to a prefab. You can't just use a string and expect Unity to know what you mean by this.

Actually your whole script doesn't make much sense. The CompareTag line in Start is totally useless since it does nothing.

Calling Instantiate every frame as long as curHealth is 0 doesn't make much sense to me. This would instantiate hundreds of objects within seconds. If you really want to recreate the player object you should destroy the old one afterwards. However that usually caused even more problems. It's usually way simpler to just "reset" your players health and move the player to the respawn position.

Also you should follow at least one common indent style because your code is formatted in a very confusing matter ;)

Comment
Add comment · 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

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

21 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 avatar image

Related Questions

Future Augment 1 Answer

Cloud recognition in Vuforia 0 Answers

Program control not entering onTriggerEnter() 1 Answer

why I am not getting highest value in my highscore textfield? 1 Answer

my gui text write over an over in a row 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