void Init() { myTransform = transform; canMove = true; canJumpAgain = true; canSlideAgain = true; canRollLeftAgain = true; canRollRightAgain = true; #if UNITY_EDITOR keyboardInput = ExtendedGameObject.SetComponent <Keyboard_Input>(gameObject); #elif UNITY_ANDROID touchInput = ExtendedGameObject.SetComponent <TouchInput>(gameObject); #endif anim = ExtendedGameObject.SetComponent <Animator>(gameObject); MainCameraGO = GameObject.Find("Main Camera"); if (MainCameraGO == null) { Debug.Log("Cant find main camera"); return; } cameraFollower = ExtendedGameObject.SetComponent <CameraFollower>(MainCameraGO); cameraFollower.followTarget = gameObject.transform; capCollider = ExtendedGameObject.SetComponent <CapsuleCollider>(gameObject); base.Init(); MakeUninvisible(); didInit = true; }
public virtual void Init() { // Cache the usual suspects iRigid = GetComponent <Rigidbody>(); iGameobject = gameObject; iTransform = transform; // Add default keyboard input default_input = iGameobject.GetComponent <Keyboard_Input>(); // Cache a reference to player controller PlayerController = iGameobject.GetComponent <BasePlayerManager>(); // Call base class init PlayerController.Init(); // With this simple vehicle code, we set the center of mass low to try to keep the car from toppling over iRigid.centerOfMass = new Vector3(0, -4f, 0); // See if we cant find an engine sound source, if we need to if (engineSoundSource == null) { engineSoundSource = iGameobject.GetComponent <AudioSource>(); } }
public virtual void Init() { myGO = gameObject; myBody = GetComponent <Rigidbody>(); myTransform = transform; default_input = myGO.AddComponent <Keyboard_Input>(); }
// main event void Awake() { // cache a ref to our transform myTransform = transform; if (!keyboardInput) { keyboardInput = GetComponent <Keyboard_Input> (); } }
public virtual void Init() { myTransform = transform; myGameObject = gameObject; myRigrdBody = rigidbody; default_Input = myGameObject.AddComponent <Keyboard_Input> (); originZ = myTransform.localPosition.z; didInit = true; }
public virtual void Init() { // cache refs to our transform and gameObject myTransform = transform; myGameObject = gameObject; myRigidBody = this.GetComponent <Rigidbody>(); // add default keyboard input default_input = myGameObject.AddComponent <Keyboard_Input>(); // grab the starting Z position to use as a baseline for Z position limiting originZ = myTransform.localPosition.z; // set a flag so that our Update function knows when we are OK to use didInit = true; }
public virtual void Init() { // cache te usual suspects iRigid = GetComponent <Rigidbody>(); iGameobject = gameObject; iTransform = transform; // add default keyboard input default_input = iGameobject.AddComponent <Keyboard_Input>(); // cache a reference to the player controller iPlayerController = iGameobject.GetComponent <BasePlayerManager>(); if (iPlayerController != null) { iPlayerController.Init(); } }
public virtual void Init() { myRigrdBody = rigidbody; myTransform = transform; myGameObject = gameObject; default_input = myGameObject.AddComponent <Keyboard_Input> (); myPlayerController = myGameObject.GetComponent <BasePlayerManager> (); if (myPlayerController != null) { myPlayerController.Init(); } }
public virtual void Init() { // cache the usual suspects myBody = GetComponent <Rigidbody>(); myGO = gameObject; myTransform = transform; // add default keyboard input default_input = myGO.AddComponent <Keyboard_Input>(); // cache a reference to the player controller myPlayerController = myGO.GetComponent <BasePlayerManager>(); if (myPlayerController != null) { myPlayerController.Init(); } }
public virtual void Init() { myRigrdBody = rigidbody; myGameObject = gameObject; myTransform = transform; default_input = myGameObject.AddComponent <Keyboard_Input>(); myPlayerController = myGameObject.GetComponent <BasePlayerManager>(); myPlayerController.Init(); myRigrdBody.centerOfMass = new Vector3(0, -4f, 0); if (engineSound == null) { engineSound = myGameObject.GetComponent <AudioSource>(); } }
// main logic public override void Init() { base.Init(); // add default keyboard input if (!default_input) { default_input = myGO.AddComponent <Keyboard_Input> (); } // cache a reference to the player controller if (!myPlayerController) { myPlayerController = myGO.GetComponent <BasePlayerManager> (); } if (myPlayerController != null) { myPlayerController.Init(); } }
// main logiv /// <summary> /// Init main instance (myTransform, myGO, myBody, myAnimator, KeybordInput), def. in Start. /// </summary> public override void Init() { // base init base.Init(); didInit = false; // cache refs to our transform and gameObject if (!myAnimator) { myAnimator = GetComponent <Animator> (); } // add default keyboard input if (!default_input) { default_input = myGO.AddComponent <Keyboard_Input> (); } // set a flag so that our Update function knows when we are OK to use didInit = true; }
public virtual void Init() { Debug.Log("BaseVehicle Init called."); // cache the usual suspects myBody = GetComponent <Rigidbody>(); myGO = gameObject; myTransform = transform; // add default keyboard input if (myGO.GetComponent <Keyboard_Input>() == null) { default_input = myGO.AddComponent <Keyboard_Input>(); } // cache a reference to the player controller myPlayerController = myGO.GetComponent <BasePlayerManager>(); // call base class init myPlayerController.Init(); // with this simple vehicle code, we set the center of mass low to try to keep the car from toppling over myBody.centerOfMass = new Vector3(0, -4f, 0); // see if we can find an engine sound source, if we need to if (engineSoundSource == null) { engineSoundSource = myGO.GetComponent <AudioSource>(); } // now lets copy over our friction and suspension values to the wheels (keeping these values in one place // rather than having to change them on each wheel is a neater way to work!) // set up curves for front and sideways values WheelFrictionCurve curveF = new WheelFrictionCurve(); curveF.extremumSlip = forwardFrictionExtremumSlip; curveF.extremumValue = forwardFrictionExtremumValue; curveF.asymptoteSlip = forwardFrictionAsymptoteSlip; curveF.asymptoteValue = forwardFrictionAsymptoteValue; curveF.stiffness = forwardFrictionStiffnessFactor; WheelFrictionCurve curveS = new WheelFrictionCurve(); curveS.extremumSlip = sidewaysFrictionExtremumSlip; curveS.extremumValue = sidewaysFrictionExtremumValue; curveS.asymptoteSlip = sidewaysFrictionAsymptoteSlip; curveS.asymptoteValue = sidewaysFrictionAsymptoteValue; curveS.stiffness = sidewaysFrictionStiffnessFactor; // set up JointSpring for the suspension settings JointSpring suspensionJointSpring = new JointSpring(); suspensionJointSpring.damper = suspensionDamper; suspensionJointSpring.spring = suspensionSpring; // front left frontWheelLeft.mass = wheelMass; frontWheelLeft.radius = wheelRadius; frontWheelLeft.suspensionDistance = suspensionDistance; frontWheelLeft.suspensionSpring = suspensionJointSpring; frontWheelLeft.forwardFriction = curveF; frontWheelLeft.sidewaysFriction = curveS; // front right frontWheelRight.mass = wheelMass; frontWheelRight.radius = wheelRadius; frontWheelRight.suspensionDistance = suspensionDistance; frontWheelRight.suspensionSpring = suspensionJointSpring; frontWheelRight.forwardFriction = curveF; frontWheelRight.sidewaysFriction = curveS; // rear left rearWheelLeft.mass = wheelMass; rearWheelLeft.radius = wheelRadius; rearWheelLeft.suspensionDistance = suspensionDistance; rearWheelLeft.suspensionSpring = suspensionJointSpring; rearWheelLeft.forwardFriction = curveF; rearWheelLeft.sidewaysFriction = curveS; // rear right rearWheelRight.mass = wheelMass; rearWheelRight.radius = wheelRadius; rearWheelRight.suspensionDistance = suspensionDistance; rearWheelRight.suspensionSpring = suspensionJointSpring; rearWheelRight.forwardFriction = curveF; rearWheelRight.sidewaysFriction = curveS; Debug.Log("BaseVehicle wheels setup and Init() complete."); }