• 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 /
  • Help Room /
avatar image
0
Question by KustaaQuasar · Feb 10, 2016 at 02:44 PM · scripting problem

Why my unity 3 script don't work on unity 4?

Hi everyone, i'm having problems whit this codes on unity 4 and can't finda why, they work perfectly on unity 3.

using UnityEngine; using System.Collections;

 //PRIMARY FUNCTIONALITY
 //    _Take player inputs
 //  _Create a vector "MoveVector"
 //  _Forcing update for TP_Motor Class
 
 //SECONDARY FUNCTIONALITY (Housekeeping)
 //  _References: 1.Character Controller Component 2.Instance of self (TP_Controller)
 //  _Initial camera check
 //  _Continous camera check (Fail safe)
 
 public class TP_Controller : MonoBehaviour 
 {
     //FIELDS
     //reference to CharacterControll component
     public static CharacterController CharacterController; 
     //reference to this instance of the TP_Controller Class
     public static TP_Controller Instance; 
 
     void Awake    () //Takes place first, right after class instances
     {
         //Assing references into our Static Fileds
         CharacterController = GetComponent("CharacterController")
             as CharacterController; 
         Instance = this;
     }
     
     void Update    () //Called every frame
     {
         //Verify main camera existence
         if (Camera.mainCamera == null) 
         //If exist, stop taking input
             return; 
 
         //Call on GetLocomotionInput
         GetLocomotionInput(); 
 
         //Tell TP_Motor to update
         TP_Motor.Instance.UpdateMotor(); 
     }
 
     void GetLocomotionInput()
     {
         //Create a variable to hold dead space
         var deadZone = 0.1f; 
 
         //Zero out (reset) MoveVector
         TP_Motor.Instance.MoveVector = Vector3.zero; 
 
         //Verify that vertical motion is outside dead space, if so, apply vertical axis input
         if(Input.GetAxis("Vertical") > deadZone || Input.GetAxis("Vertical") < -deadZone)
             TP_Motor.Instance.MoveVector += new Vector3(0, 0, Input.GetAxis("Vertical"));
 
         //Verify that vertical motion is outside dead space, if so, apply horizontal axis input
         if(Input.GetAxis("Horizontal") > deadZone || Input.GetAxis("Horizontal") < -deadZone)
             TP_Motor.Instance.MoveVector += new Vector3(Input.GetAxis("Horizontal"), 0, 0);
     }
 }



 using UnityEngine;
 using System.Collections;
 
 // PRIMARY FUNCTIONLITY
 //  _MoveVector --> world space motion
 //      .Convert MoveVector to a vector in world space relative to character motion
 //        .Normalazing our vector to 0-1
 //        .* by user-set magnitude
 //      .Convert "units per update" to "units per second"
 //      .Apply the motion
 
 // SECONDATY FUNCTIONALITY
 // _If moving, rotate character to match camera rotation
 
 public class TP_Motor : MonoBehaviour 
 {
     //FIELDS
     //Instance (static) reference to this instance of TP_Motor
     public static TP_Motor Instance; 
     //MoveSpeed (Public) multiplier for our normalized vector
     public float MoveSpeed = 10f; 
 
     //PROPIETY
     //MoveVector - The vector that is accesed by TP_Controller + procesed by TP_Motor
     public Vector3 MoveVector {get; set; } 
 
     void Awake () //Assing initial references fields (instances)
     {
         Instance = this;
     }
     
     public void UpdateMotor () 
     {
         //Call on SnapAlignCharacterWithCamera()
         SnapAlignCharactertWhitCamera (); 
         //Call on ProcessMotion()
         ProcessMotion ();
     }
 
     void ProcessMotion ()
     {
         //Transform MoveVector to world space
         MoveVector = transform.TransformDirection(MoveVector);
 
         //Normalize MoveVector by MoveSpeed
         if(MoveVector.magnitude > 1)
             MoveVector = Vector3.Normalize(MoveVector);
 
         //Multiply MoveVector by MoveSpeed
         MoveVector *= MoveSpeed;
 
         //Multiply MoveVector by DeltaTime
         MoveVector *= Time.deltaTime;
 
         //Move the character in world space
         TP_Controller.CharacterController.Move(MoveVector);
     }
 
     void SnapAlignCharactertWhitCamera ()
     {
         //Are we moving?
         if(MoveVector.x != 0 || MoveVector.z != 0) 
         {
             //If so, rotate the character to match direction camera is facing
             transform.rotation = Quaternion.Euler 
                 (transform.eulerAngles.x, 
                  Camera.mainCamera.transform.eulerAngles.y, 
                  transform.eulerAngles.z); 
         }
     }
 }
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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Trying to restrict movement to bounds of screen using MathF.Clamp() 2 Answers

help! i am a newbie here and i got a problem in scripting 0 Answers

Why Collider2D size Y changes affects child object position 0 Answers

Why is my cube not following the other the way i want ? 1 Answer

How to Undo a lot of created objects at once? [Solved] 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