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
-1
Question by KadoshAdonai · Sep 09, 2017 at 01:17 AM · animationaiscripting beginnermodelartificial intelligence

Transform an object in other

=======

Hi, I'm creating a game, and some of the mechanics I want, is a power, a staff turns into a snake, how can I do this in C #? The snake must have animations, AI.

Comment
Add comment · Show 1
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 Kishotta · Sep 09, 2017 at 02:00 AM 0
Share

You're going to have to be $$anonymous$$UCH more specific on your questions. Where exactly are you stuck on this problem? What have you tried? Can you be more specific on what it is you're trying to achieve?

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by shadowpuppet · Sep 09, 2017 at 03:02 AM

trigger it somehow and instantiate a prefab. like if the player gets close to the staff or if the player has a certain amount of points or whatever condition is required to turn the staff into a snake. The snake will be a prefab with animation and AI scripts on it. When the condition is met to make the staff change, destroy it and instantiate the snake. The code below is if the player gets close to the staff. The staff needs a trigger collider and this script.

 using UnityEngine;
 using System.Collections;
 
 public class staffChange : MonoBehaviour {
 public GameObject  snake;//this is where you drag the snake prefab
 
 void OnTriggerEnter(Collider other) {
             if(other.tag == "player")
             {
 
 Instantiate(snake, transform.position , transform.rotation);
 Destroy(gameObject);
 }
 }
 }

for a score requirement of 50 points:

  using UnityEngine;
  using System.Collections;
  
  public class staffChange : MonoBehaviour {
  public GameObject  snake;//this is where you drag the snake prefab
 public GameObject PlayerScore;//this is where you drag the  gameobject with scoring script
  MonoBehaviour score;// this is the value in the scoring script of the players score
 void start()
 score =  PlayerScore.GetComponent<scoreScript>();
  }
 if( scoreScript.score = 50)
 {
  
  Instantiate(snake, transform.position , transform.rotation);
  Destroy(gameObject);
 }
 }
 }

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 IsaiahKelly · Sep 09, 2017 at 03:21 AM 0
Share

Oh wow, I created basically the same (but less comprehensive) answer before realizing someone had beat me to it while I was writing it. LOL

avatar image
0

Answer by IsaiahKelly · Sep 09, 2017 at 03:11 AM

Just create a snake prefab with all the functions you need. Then create a script and attach it to the staff that will replace it with this new snake prefab. Something like this:

 using UnityEngine;
 
 public class StaffSwappingScript : MonoBehaviour
 {
     public GameObject swapObject; // drag snake prefab onto this from the editor.
 
     // call this when you want to switch to the "swapObject" object.
     public void Swap()
     {
         // spawn replacement object with same position and rotation.
         var replacement = Instantiate(swapObject, transform.position, transform.rotation);
 
         // might want to also make sure it has the same parent?
         replacement.transform.parent = transform.parent;
 
         // destroy the old object we're replacing.
         Destroy(gameObject);
     }
 }

This script could be attached to the staff itself for onetime switching or the player and expanded to allow for switching back and forth.

Note: "transform" and "gameObject" are helper functions to easily access the GameObject and Transform the script is attached to. If you attach the script to something else this code will need to be modified to make it work.

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

215 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 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 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

How do I rewrite this script to use an animator ? 0 Answers

Making a first person rpg enemy AI 2 Answers

Conflicting animations (attack and idle) 1 Answer

Character Animation won't work with FPS scripts 1 Answer

Model stays at the end of my animation D:? 0 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