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
0
Question by ezecapo99 · Mar 13, 2018 at 08:45 AM · networkinganimatorplayermovement script

help animator not acces other gameobject,Animator acces other gameobject?

hello everyone I'm half bad for English, I need your help please I was quietly making a script so I can move the character but I throw the following error:

MissingComponentException: There is no 'Animator' attached to the "Net" game object, but a script is trying to access it. You probably need to add to Animator to the game object "Net". Or your script needs to check if the component is attached before:

movimiento.cs

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 public class Movimiento : MonoBehaviour {
     //variables
     private float animSpeed = 1.5f;
     private float back = 2.0f;
     private float forward = 7.0f;
     private float rotateSpeed = 4.0f;
     private float jumpPower = 6.0f;
     private float jumpLimit = 1.5f;
     public GameObject playerobj;
     bool isGrounded = true;
     private Animator anim;
     private Rigidbody rb;
     private CapsuleCollider col;
     private Vector3 velocity;
     // Use this for initialization
     void Start () {
       
         anim = GetComponent<Animator>();
         col = GetComponent<CapsuleCollider>();
         rb = GetComponent<Rigidbody>();
     }
 
     // Update is called once per frame
     void FixedUpdate() {
             Transform tranf = playerobj.transform;
         float h = Input.GetAxis("Horizontal");
         float v = Input.GetAxis("Vertical");
         anim.SetFloat("Speed", v);
         anim.SetFloat("Direction", h);
         anim.speed = animSpeed;
         rb.useGravity = true;
  
 
 
         velocity = new Vector3(0, 0, v);
         velocity = playerobj.transform.TransformDirection(velocity);
 
         if (v > 0.1)
         {
             velocity *= forward;
         } else if (v < -0.1)
         {
             velocity *= back;
         }
         
         if (Input.GetButtonDown("Jump") && isGrounded)
         {
 
             rb.AddForce(Vector3.up * jumpPower, ForceMode.VelocityChange);
             anim.SetBool("Jump", true);
 
         }
         else
         {
             anim.SetBool("Jump", false);
         }
 
 
 
     playerobj.transform.localPosition += velocity * Time.fixedDeltaTime;
     playerobj.transform.Rotate(0, h * rotateSpeed, 0);
         
     }
     void OnCollisionEnter(Collision collision)
     {
         Debug.Log("Entered");
         if (collision.gameObject.CompareTag("Ground"))
         {
             isGrounded = true;
         }
     }
 
     void OnCollisionExit(Collision collision)
     {
         Debug.Log("Exited");
         if (collision.gameObject.CompareTag("Ground"))
         {
             isGrounded = false;
         }
     }
 }

network.cs

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 using SocketIO;
 using System.Text.RegularExpressions;
 
 public class network : MonoBehaviour {
 
     public SocketIOComponent socket;
     public Movimiento mov;
     public Player player;
 
     // Use this for initialization
     void Start () {
         StartCoroutine(ConnectToServer());
         socket.On("USER_CONNECTED", OnUser);
         socket.On("PLAY", OnPlay);
 
     }
 
     IEnumerator ConnectToServer()
     {
         yield return new WaitForSeconds(0.5f);
         socket.Emit("conectar");
         Dictionary<string, string> data = new Dictionary<string, string>();
         Vector3 position = new Vector3(10, 0, 11);
         data["position"] = position.x + "," + position.y + "," + position.z;
         socket.Emit("PLAY", new JSONObject(data));
     }
     void OnUser (SocketIOEvent obj)
     {
         GameObject otherPlater = GameObject.Instantiate(player.gameObject, player.position, Quaternion.identity) as GameObject;
         Player otherPlayerCom = otherPlater.GetComponent<Player>();
         otherPlater.transform.position = JsonToVecter3(JsonToString(obj.data.GetField("position").ToString(), "\""));
         otherPlayerCom.id = JsonToString(obj.data.GetField("id").ToString(), "\"");
     }
     void OnPlay(SocketIOEvent obj)
     {
         GameObject ply = GameObject.Instantiate(player.gameObject, player.position, Quaternion.identity) as GameObject;
         Player playerCom = ply.GetComponent<Player>();
         
         ply.transform.position = JsonToVecter3(JsonToString(obj.data.GetField("position").ToString(), "\""));
         playerCom.id = JsonToString(obj.data.GetField("id").ToString(), "\"");
         mov.playerobj = ply;
     }
     Vector3 JsonToVecter3(string target)
     {
 
         Vector3 newVector;
         string[] newString = Regex.Split(target, ",");
         newVector = new Vector3(float.Parse(newString[0]), float.Parse(newString[1]), float.Parse(newString[2]));
 
         return newVector;
 
     }
 
     string JsonToString(string target, string s)
     {
 
         string[] newString = Regex.Split(target, s);
 
         return newString[1];
 
     }
 
 
 }





alt text

wadwadaw.png (249.7 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

129 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

Related Questions

Alfernative to transform.Move? Unet 1 Answer

Rotate game object and then return to its original rotation 1 Answer

How to display player ID on client sides? 1 Answer

UNET ReplacePlayerForConnection problem 0 Answers

Network Game Player reference 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