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 MrGamingdwarf · Sep 23, 2013 at 01:14 AM · move an object

Replace A Component Then Crashes

Using Unity 4.2.1f4. Whenever I add my script which requires a Character Controller but when I add the script Unity ask to replace the current collider, I click add or replace and it crashes. Am I doing something wrong? I am new to Unity. Here my MovementController script:

 using UnityEngine;
 using System.Collections;
 
 [RequireComponent (typeof(CharacterController))]
 [RequireComponent (typeof(Animation))]
 [RequireComponent (typeof(PlayerInput))]
 public class MovementController : MonoBehaviour {
     
     public enum State {
         Idle,
         Init,
         Setup,
         Run
     }
     
     public enum Rotate {
         left = -1,
         none = 0,
         right = 1
     }
     
     public enum Move {
         backward = -1,
         none = 0,
         forward = 1
     }
 
     private Transform myTransform;
     private CharacterController myController;
     private Vector3 myDirection;
     private CollisionFlags myCollisionFlags;
     
     public float RotationSpeed = 100;
     public float MovementSpeed = 5;
     public float StrafeSpeed = 3;
     public float Gravity = 20;
     public float AirTime = 0;
     public float FallTime = 0.5f;
     public float JumpHeight = 8;
     public float JumpTime = 1.5f;
     
     public AnimationClip RotateAnimation;
     public AnimationClip MoveAnimation;
     public AnimationClip StrafeAnimation;
     public AnimationClip JumpAnimation;
     public AnimationClip FallAnimation;
     
     public bool Jump;
     
     private Rotate rotate;
     private Move move;
     private Rotate strafe;
     private State state;
     
     
     void Awake() {
         myTransform = transform;
         myController = GetComponent<CharacterController>();
         
         state = State.Init;
     }
     
     IEnumerator Start () {
         while(true) {
             switch(state) {
             case State.Init:
                 Init();
                 break;
             case State.Setup:
                 Setup();
                 break;
             case State.Run:
                 ActionPicker();
                 break;
             }
             yield return null;
         }
     }
     
     void Init() {
         if(!GetComponent<CharacterController>()) return;
         if(!GetComponent<Animation>()) return;
         
         state = State.Setup;
     }
     
     void Setup() {
         myDirection = Vector3.zero;
         rotate = Rotate.none;
         move = Move.none;
         strafe = Rotate.none;
         Jump = false;
         
         state = State.Run;
     }
     
     void ActionPicker() {
         if(rotate != Rotate.none) {
             myTransform.Rotate(0, (int)rotate * Time.deltaTime * RotationSpeed, 0);
             Rotating();
         }
         if(myController.isGrounded) {
             AirTime = 0;
             
             myDirection = new Vector3((int)strafe, 0, (int)move);
             myDirection = myTransform.TransformDirection(myDirection).normalized;
             myDirection *= MovementSpeed;
             if(move != Move.none) {
                 Moving();
             }else if(strafe != Rotate.none) {
                 Strafing();
             }else{
                 Idle();
             }
             if(Jump) {
                 if(AirTime < JumpTime) {
                     myDirection.y += JumpHeight;
                     Jumping();
                     Jump = false;
                 }
             }
         }else{
             if((myCollisionFlags & CollisionFlags.CollidedBelow) == 0) {
                 AirTime += Time.deltaTime;
                 
                 if(AirTime > FallTime) {
                     Falling();
                 }
             }
         }
         
         myDirection.y -= Gravity * Time.deltaTime;
         myCollisionFlags = myController.Move(myDirection * Time.deltaTime);
     }
     
     void MoveAction(Move z) {
         move = z;
     }
     
     void RotateAction(Rotate y) {
         rotate = y;
     }
     
     void StrafeAction(Rotate x) {
         strafe = x;
     }
     
     void JumpAction() {
         Jump = true;
     }
     
     void Rotating() {
         
     }
     
     void Moving() {
         
     }
     
     void Strafing() {
         
     }
     
     void Jumping() {
         
     }
     
     void Falling() {
         
     }
     
     void Idle() {
         
     }
     
 }
 
Comment
Add comment
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

0 Replies

· Add your reply
  • Sort: 

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

15 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

Related Questions

Rotating an Object while Moving 0 Answers

how to work my game 0 Answers

Object rotating around object at two levels 1 Answer

Translate speed keeps changing 1 Answer

Unity3D grenade not exploding correctly 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