Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 $$anonymous$$ · Dec 05, 2017 at 05:10 PM · prefabcopy

Duplicate a Prefab

Hello, so i've made a pretty simple but good game. But today when i tried to make some enemies i duplicated a enemy wich was my "Zombie". The original "Zombie" worked with the animations and when he came up to me he hit me, but the copied version just walked up to me and didn't hurt me. So what sould i do?

The script for the chasing is here:

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class ChaseZombie : MonoBehaviour
 {
     public Transform player;
     static Animator anim;
 
     void Start()
     {
         anim = GetComponent<Animator>();
     }
 
     void Update()
     {
         Vector3 direction = player.position - this.transform.position;
         float angle = Vector3.Angle(direction, this.transform.forward);
         if (Vector3.Distance(player.position, this.transform.position) < 45 && angle < 180)
         {
             direction.y = 0;
 
             this.transform.rotation = Quaternion.Slerp(this.transform.rotation,
                                         Quaternion.LookRotation(direction), 0.1f);
             anim.SetBool("isAttacking", false);
             if (direction.magnitude > 1)
             {
                 this.transform.Translate(0, 0, 0.05f);
                 anim.SetBool("iswalking", true);
                 anim.SetBool("isAttacking", false);
             }
             else
             {
                 anim.SetBool("iswalknig", false);
                 anim.SetBool("isAttacking", true);
             }
 
         }
         else
         {
             anim.SetBool("iswalking", true);
             anim.SetBool("isAttacking", false);
         }
     }
 }
Comment
Add comment · Show 6
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 megabrobro · Dec 05, 2017 at 05:19 PM 0
Share

Double-check in the Inpsector of the Prefab. Are all the objects etc dragged into all the public fields you created? I know I had similar problems where I'd saved a gameobject as a prefab, the one in the Hierarchy that I first created worked fine, but the prefab had some items missing, because they were impossible to drag into it at "prefab level" (for want of better ter$$anonymous$$ology lol) . I had to then find a way of adding the objects via code ( ins$$anonymous$$d of using public (and then draggin in inpsector).

$$anonymous$$ethods such as GameObject.FindObjectWithTag() helped me here.

I hope this helps

avatar image ShadyProductions · Dec 05, 2017 at 05:29 PM 0
Share

It's probably the damaging script that has an issue, not this one..

avatar image megabrobro ShadyProductions · Dec 05, 2017 at 05:30 PM 0
Share

Yes defeintely agreed. I hadnt read properly that is working other than not hurting the player

avatar image megabrobro megabrobro · Dec 05, 2017 at 05:32 PM 0
Share

would the fact the "iswalking" is spelt wrong on line 34 cause the script to not compile?

Show more comments

2 Replies

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

Answer by danteswap · Dec 05, 2017 at 05:25 PM

Delete All Zombies From hierarchy Than Add the Working one In Scene And test if Animations Are Working, if Working then Select The Zombie From Scene duplicate it by ctrl+c , ctrl+v, And test if both Are Working Or Not. if Working Then Delete duplicated one And Create The prefab From 1st Zombie By dragging it into The Assets folder When Done Delete the zombie In the Scene then drag Created prefab from Assets folder to Scene And Duplicate it Like 10 Or 20 Time as per your Need .

Comment
Add comment · Show 8 · 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 megabrobro · Dec 05, 2017 at 05:27 PM 0
Share

Ctrl-D duplicates in Unity no?

avatar image danteswap megabrobro · Dec 05, 2017 at 05:30 PM 0
Share

yes it Does But c,v, also does :)

avatar image megabrobro danteswap · Dec 05, 2017 at 05:33 PM 0
Share

haha didnt realise that till now

Show more comments
avatar image megabrobro · Dec 05, 2017 at 05:28 PM 0
Share

Also OP remember, if you make a change to the prefabbed object from within the hieracrchy, you need to click 'Apply' on the prefab for it to apply to every instance of the prefab from then on, otherwise you're only affecting the one instance and not the prefab itself

avatar image $$anonymous$$ · Dec 05, 2017 at 05:33 PM 0
Share

Ok, i deleted them all but only the first one i pasted worked. Thanks for all help everyone thought!

avatar image megabrobro $$anonymous$$ · Dec 05, 2017 at 05:33 PM 0
Share

Nice !!!!!

avatar image danteswap $$anonymous$$ · Dec 05, 2017 at 05:36 PM 0
Share

Always happy To help :)

avatar image
0

Answer by $$anonymous$$ · Dec 05, 2017 at 05:39 PM

So i draged the prefab into the assets folder but again only the first one worked, so what should or can i test now?

Comment
Add comment · Show 6 · 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 danteswap · Dec 05, 2017 at 05:45 PM 0
Share

If first One Worked All Duplicates Should work Same Unless The Reference On Duplicates Are To the First One .It doesn't Sound Good But need some shot Or Video For understanding whats going on.

avatar image $$anonymous$$ · Dec 05, 2017 at 05:45 PM 0
Share

It's fixed now so thank you all guys! Every little step made one big! Credits to @danteswap @megabrobro @shadyproductions .

avatar image danteswap $$anonymous$$ · Dec 05, 2017 at 05:46 PM 0
Share

Wow What $$anonymous$$ade it Work Now :)

avatar image $$anonymous$$ danteswap · Dec 05, 2017 at 05:48 PM 0
Share

yeah long story short, i copied the prefab and it went wrong but later i made a new script pasted the old script in and it's done! So remember you can't copy scripts. Thanks!

Show more comments

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

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

Related Questions

Instantiated coconuts not working 0 Answers

Using Instantiate on a Rigidbody rather than a whole GameObject 1 Answer

Creating Prefab causes scripts to break, Copy/Paste Gameobject doesn't 0 Answers

Instatiate prefab at another prefab issue 1 Answer

Prefab Variables Changing in the Original, Not the Copies 2 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