playMaker

Author Topic: Trying to get unity to read and control variables in scripts but to no success  (Read 881 times)

paradiseprime

  • Full Member
  • ***
  • Posts: 105
Here is my script.
using FishNet.Object;
using FishNet.Object.Synchronizing;
using FishNet.Transporting;
using System.Collections;
using UnityEngine;
using HutongGames.PlayMaker;

namespace Client.Health
{
    public class ClientHealth : NetworkBehaviour
    {
        [SyncVar(Channel = Channel.Unreliable, ReadPermissions = ReadPermission.Observers, SendRate = 0.1f, OnChange = nameof(OnServerHealth))]
        private float ServerHealth;
        public float LocalHealth;

        private void OnServerHealth(float prev, float next, bool asServer)
        {
            if (!asServer)
                LocalHealth = ServerHealth;
            else
                Debug.Log($"New health value: {next}.");
        }
    }
}


I keep getting this error: [TargetParameterCountException: Number of parameters specified does not match the expected number]

I am trying to use Set Property on the script to get the private float, ServerHealth but it just doesnt work. What am I doing wrong?

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7616
    • jinxtergames
Hi.
Its a bit confusing what you want here.

a private float you can't access since it's private.
so this script can't set the ServerHealth.

Quote
Set Property on the script to get the private float
if you want to get a variable. you need to use 'Get Property' , but you can only do that to a public float, so you can get the LocalHealth since its public