Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - defender1213

Pages: [1]
1
TNet 3 Support / How can i make server-raycast system?
« on: February 11, 2018, 07:24:41 AM »
Ok please help me!!!How can i make servers shooting system that will calculate where thi bullet goes?

2
TNet 3 Support / I tryed to make animator sync script,but it has isues
« on: January 29, 2018, 01:50:43 PM »
I tryed to make animator sync script,but it has isues and dont works correct at all,please help me to fix this script:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using TNet;
public class TN_Animator : TNBehaviour{
    Animator anim;
    [SerializeField] int updates=10;
    float uptouse=0;
    float[] data;
    int[] param;
    string[] _name;
    void Awake()
    {
        anim = GetComponent<Animator>();
        param = new int[anim.parameterCount];
        _name = new string[anim.parameterCount];
        for(int i = 0; i != anim.parameterCount; i++)
        {
            if (anim.parameters.type == AnimatorControllerParameterType.Bool) param = 0;
            else if (anim.parameters.type == AnimatorControllerParameterType.Float) param = 1;
            else if (anim.parameters.type == AnimatorControllerParameterType.Int) param = 2;
            else if (anim.parameters.type == AnimatorControllerParameterType.Trigger) param = 3;
            _name =  anim.parameters.name;
        }
        data = new float[anim.parameterCount];
        uptouse = updates;
    }
    void FixedUpdate()
    {
        if (tno.isMine)
        {
            uptouse -= Time.fixedDeltaTime;
            if (uptouse <= 0)
            {
                for (int i = 0; i != anim.parameterCount; i++)
                {
                    if (Equals(param, 0)) if (Equals(anim.GetBool(_name), true)) data = 0; else data = 1;
                    else if (Equals(param, 1)) data = anim.GetFloat(_name);
                    else if (Equals(param, 2)) data = anim.GetInteger(_name);
                    else if (Equals(param, 3)) if (Equals(anim.GetBool(_name), true)) data = 0; else data = 1;
                }
                tno.SendQuickly("UpPram", Target.Others, data);
                Debug.Log(data);
                uptouse = updates;
            }           

        }
    }
    [RFC]void UpPram(float[] data)
    {
        for(int i=0;i!=data.Length;i++)
        {
            if (Equals(param, 0)) if (Equals(data,0 ))anim.SetBool(_name,true); else anim.SetBool(_name, false);
            else if (Equals(param, 1)) anim.SetFloat(_name, data);
            else if (Equals(param, 2)) anim.SetInteger(_name, (int)data);
            else if(Equals(param, 3)) if (Equals(data, 0)) anim.SetTrigger(_name);
        }
        this.data = data;
    }
   
}

3
NGUI 3 Support / I tryed to make animator sync script,but it has isues
« on: January 29, 2018, 01:44:39 PM »
I tryed to make animator sync script,but it has isues and dont works correct at all,please help me to fix this script:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using TNet;
public class TN_Animator : TNBehaviour{
    Animator anim;
    [SerializeField] int updates=10;
    float uptouse=0;
    float[] data;
    int[] param;
    string[] _name;
    void Awake()
    {
        anim = GetComponent<Animator>();
        param = new int[anim.parameterCount];
        _name = new string[anim.parameterCount];
        for(int i = 0; i != anim.parameterCount; i++)
        {
            if (anim.parameters.type == AnimatorControllerParameterType.Bool) param = 0;
            else if (anim.parameters.type == AnimatorControllerParameterType.Float) param = 1;
            else if (anim.parameters.type == AnimatorControllerParameterType.Int) param = 2;
            else if (anim.parameters.type == AnimatorControllerParameterType.Trigger) param = 3;
            _name =  anim.parameters.name;
        }
        data = new float[anim.parameterCount];
        uptouse = updates;
    }
    void FixedUpdate()
    {
        if (tno.isMine)
        {
            uptouse -= Time.fixedDeltaTime;
            if (uptouse <= 0)
            {
                for (int i = 0; i != anim.parameterCount; i++)
                {
                    if (Equals(param, 0)) if (Equals(anim.GetBool(_name), true)) data = 0; else data = 1;
                    else if (Equals(param, 1)) data = anim.GetFloat(_name);
                    else if (Equals(param, 2)) data = anim.GetInteger(_name);
                    else if (Equals(param, 3)) if (Equals(anim.GetBool(_name), true)) data = 0; else data = 1;
                }
                tno.SendQuickly("UpPram", Target.Others, data);
                Debug.Log(data);
                uptouse = updates;
            }           

        }
    }
    [RFC]void UpPram(float[] data)
    {
        for(int i=0;i!=data.Length;i++)
        {
            if (Equals(param, 0)) if (Equals(data,0 ))anim.SetBool(_name,true); else anim.SetBool(_name, false);
            else if (Equals(param, 1)) anim.SetFloat(_name, data);
            else if (Equals(param, 2)) anim.SetInteger(_name, (int)data);
            else if(Equals(param, 3)) if (Equals(data, 0)) anim.SetTrigger(_name);
        }
        this.data = data;
    }
   
}

4
Misc Archive / Shooter on tnet... please help
« on: October 21, 2017, 01:47:14 PM »
Please give me example code of shooter on tnet(with hp) ,because my variant contains a lot of functions Find() and bad optimized...

5
TNet 3 Support / Shoter on TNET.HELP please!!!
« on: October 20, 2017, 03:52:14 AM »
How can i create simple shooter using tnet?or how i can send gameobjects using tno.Send()? or please tell me about other functions!

6
TNet 3 Support / Help Please(sync bugs...)
« on: October 13, 2017, 04:16:12 PM »
I have a problem with sinc pos and rot,one player,who is in car can ride normal,but other player don't see it,because it stay(pos not changes)tis script.Help please to fix it!(I'am sorry if my English is bad...)
  1. using UnityEngine;
  2. using TNet;
  3.  
  4. /// <summary>
  5. /// Extended car that adds TNet-based multiplayer support.
  6. /// </summary>
  7. [RequireComponent(typeof(TNObject))]
  8. public class ExampleCar : ExampleCarNoNetworking
  9. {
  10.     /// <summary>
  11.     /// Maximum number of updates per second when synchronizing input axes.
  12.     /// The actual number of updates may be less if nothing is changing.
  13.     /// </summary>
  14.     private NetworkCar ncar;
  15.         [Range(1f, 20f)]
  16.         public float inputUpdates = 10f;
  17.  
  18.         /// <summary>
  19.         /// Maximum number of updates per second when synchronizing the rigidbody.
  20.         /// </summary>
  21.  
  22.         [Range(0.25f, 5f)]
  23.         public float rigidbodyUpdates = 1f;
  24.  
  25.         /// <summary>
  26.         /// We want to cache the network object (TNObject) we'll use for network communication.
  27.         /// If the script was derived from TNBehaviour, this wouldn't have been necessary.
  28.         /// </summary>
  29.  
  30.         [System.NonSerialized]
  31.         public TNObject tno;
  32.  
  33.         protected Vector2 mLastInput;
  34.         protected float mLastInputSend = 0f;
  35.         protected float mNextRB = 0f;
  36.     bool InCar;
  37.  
  38.         protected override void Awake ()
  39.         {
  40.                 base.Awake();
  41.                 tno = GetComponent<TNObject>();
  42.         ncar = GetComponent<NetworkCar>();
  43.  
  44.     }
  45.  
  46.         /// <summary>
  47.         /// Only the car's owner should be updating the movement axes, and the result should be sync'd with other players.
  48.         /// </summary>
  49.  
  50.         protected override void Update ()
  51.         {
  52.         // Only the player that actually owns this car should be controlling it
  53.         if (!ncar._allowToEnter || !tno.isMine || !ncar.InCar)
  54.             return;
  55.         base.Update();
  56.         float time = Time.time;
  57.         float delta = time - mLastInputSend;
  58.         float delay = 1f / inputUpdates;
  59.         // Update the input axes
  60.  
  61.  
  62.         // Don't send updates more than 20 times per second
  63.         if (delta > 0.05f)
  64.                 {
  65.                         // The closer we are to the desired send time, the smaller is the deviation required to send an update.
  66.                         float threshold = Mathf.Clamp01(delta - delay) * 0.5f;
  67.  
  68.             // Если отклонение является достаточно значительным, отправьте обновление другим игрокам
  69.             if (Tools.IsNotEqual(mLastInput.x, mInput.x, threshold) ||
  70.                                 Tools.IsNotEqual(mLastInput.y, mInput.y, threshold))
  71.                         {
  72.                                 mLastInputSend = time;
  73.                                 mLastInput = mInput;
  74.                                 tno.Send("SetAxis", Target.OthersSaved, mInput);
  75.                         }
  76.                 }
  77.  
  78.                 // Since the input is sent frequently, rigidbody only needs to be corrected every couple of seconds.
  79.                 // Faster-paced games will require more frequent updates.
  80.                 if (mNextRB < time)
  81.                 {
  82.                         mNextRB = time + 1f / rigidbodyUpdates;
  83.                         tno.Send("SetRB", Target.OthersSaved, mRb.position, mRb.rotation, mRb.velocity, mRb.angularVelocity);
  84.                 }
  85.         }
  86.  
  87.         /// <summary>
  88.         /// RFC for the input will be called several times per second.
  89.         /// </summary>
  90.  
  91.         [RFC]
  92.         protected void SetAxis (Vector2 v) { mInput = v; }
  93.  
  94.         /// <summary>
  95.         /// RFC for the rigidbody will be called once per second by default.
  96.         /// </summary>
  97.  
  98.         [RFC]
  99.         protected void SetRB (Vector3 pos, Quaternion rot, Vector3 vel, Vector3 angVel)
  100.         {
  101.                 mRb.position = pos;
  102.                 mRb.rotation = rot;
  103.                 mRb.velocity = vel;
  104.                 mRb.angularVelocity = angVel;
  105.         }
  106. }
  107.  
another script Network Car is used too.
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using TNet;
  5. public class NetworkCar : TNBehaviour
  6. {
  7.     public ExampleCar CC;
  8.     public Camera cam;
  9.     public bool InCar;
  10.     public bool _allowToEnter = false;
  11.     GameObject player;
  12.     protected void Update()
  13.     {
  14.         /*if (!InCar)
  15.         {
  16.             CC.enabled = false;
  17.         }*/
  18.         /*if (!tno.isMine)
  19.         {
  20.             CC.enabled = false;
  21.             cam.enabled = false;
  22.         }*/
  23.         if (!tno.isMine)
  24.             return;
  25.         if (!_allowToEnter)
  26.             return;
  27.         if (InCar)
  28.         {
  29.             if (Input.GetKeyDown(KeyCode.E) && _allowToEnter == false && InCar)
  30.             {
  31.                 Debug.Log("Exit");
  32.                 CarState(false);
  33.                 tno.Send("CarState",Target.OthersSaved,false);
  34.                 InCar = false;
  35.             }
  36.         }
  37.         if (InCar)
  38.             return;
  39.  
  40.         if (Input.GetKeyUp(KeyCode.E) && _allowToEnter == true && !InCar)
  41.         {
  42.             Debug.Log("Enter");
  43.             CarState(true);
  44.             tno.Send("CarState", Target.OthersSaved,true);
  45.             InCar = true;
  46.         }      
  47.     }
  48.     void OnTriggerEnter(Collider other)
  49.     {
  50.         if (other.tag == "Player")
  51.         {
  52.             _allowToEnter = true;
  53.             player = other.gameObject;
  54.         }
  55.     }
  56.     void OnTriggerExit(Collider other)
  57.     {
  58.         if (other.tag == "Player")
  59.         {
  60.             player = other.gameObject;
  61.             _allowToEnter = false;
  62.         }
  63.     }
  64.     [RFC(2)]void CarState(bool someone)
  65.     {
  66.         player.GetComponent<NetworkPlayer>().ChConState(!someone);
  67.         player.GetComponent<NetworkPlayer>().cam.gameObject.SetActive(!someone);
  68.         _allowToEnter = someone;
  69.         player.GetComponent<NetworkPlayer>().UpVisualState(!someone);
  70.  
  71.     }
  72.     }
  73.  

Pages: [1]