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 /
  • Help Room /
avatar image
0
Question by Lenin1337 · Jul 08, 2016 at 01:04 PM · 3d

The children help with the code, that gets the character is controlled from the

The children help with the code, that gets the character is controlled from the keyboard and moving the crosshair cursor as much lead there and directed sight. I would like to replace it and put the joystick and fire button, but do not know how to try out is all that you can, you're my last hope

PLAYER using UnityEngine; using System.Collections;

[RequireComponent (typeof (PlayerController))] [RequireComponent (typeof (GunController))] public class Player : LivingEntity {

 public float moveSpeed = 5;

 public Crosshairs crosshairs;

 Camera viewCamera;
 PlayerController controller;
 GunController gunController;
 
 protected override void Start(){
     base.Start();
 }

 void Awake(){
     controller = GetComponent<PlayerController>();
     gunController = GetComponent<GunController>();
     viewCamera = Camera.main;
     FindObjectOfType<Spawner> ().OnNewWave += OnNewWave;
 }

 void OnNewWave( int waveNumber){
     health = startingHealth;
     gunController.EquipGun (waveNumber - 1);
 }

 void Update(){
            // Movement input
     Vector3 moveInput = new Vector3(Input.GetAxisRaw("Horizontal"), 0, Input.GetAxisRaw("Vertical"));
     Vector3 moveVelocity = moveInput.normalized * moveSpeed;
     controller.Move(moveVelocity);
     
            // Look input
     Ray ray = viewCamera.ScreenPointToRay(Input.mousePosition);
     Plane groundPlane = new Plane(Vector3.up, Vector3.up * gunController.GunHeight);
     float rayDistance;
     
         if (groundPlane.Raycast(ray, out rayDistance)){
             Vector3 point = ray.GetPoint(rayDistance);
             //Debug.DrawLine(ray.origin,point,Color.red);
         controller.LookAt(point);
         crosshairs.transform.position = point;
         crosshairs.DetectTargets (ray);    
         if((new Vector2 (point.x, point.z) - new Vector2 (transform.position.x, transform.position.z)).sqrMagnitude > 1){
                 gunController.Aim (point);
             }
         }
     
            // Weapon input
          if (Input.GetMouseButton(0)){
         gunController.OnTriggerHold();
           }
          if (Input.GetMouseButtonUp(0)){
         gunController.OnTriggerRelease();
     }
     if (Input.GetKeyDown (KeyCode.R)) {
         gunController.Reload ();
     }

     if (transform.position.y < -10) {
         TakeDamage (health);
     }
 }

 public override void Die(){

     AudioManager.instance.PlaySound ("Play Death", transform.position);
     base.Die ();
 }

} PLAYER CONTROLLER

using UnityEngine; using System.Collections;

[RequireComponent (typeof (Rigidbody))] public class PlayerController : MonoBehaviour {

 Vector3 velocity;
 Rigidbody myRigidbody;

 void Start () {
     myRigidbody = GetComponent<Rigidbody>();
 
 }
 

 public void Move(Vector3 _velocity) {
     velocity = _velocity;    

 }

 public void LookAt (Vector3 lookPoint) {
     Vector3 heightCorrectedPoint = new Vector3( lookPoint.x, transform.position.y, lookPoint.z);
     transform.LookAt(heightCorrectedPoint    );
 }

 void FixedUpdate(){
     myRigidbody.MovePosition(myRigidbody.position + velocity *Time.fixedDeltaTime);

 }

}

1.png (146.1 kB)
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

46 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

Related Questions

How do I Find which collider has been triggered during onTriggerEnter() event -1 Answers

Error connect dk2 with unity 5 0 Answers

i5 or i7 for Unity Projects? 2 Answers

An object reference is required to access non-static member (CS0120) 1 Answer

Texturizing/Detailing Characters 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