public override void Replicate(NetworkObjectState state) { NetworkSnakeState snakeState = new NetworkSnakeState(); state.GetState(snakeState); snake.ReplicateState(snakeState); }
public void ReplicateState(NetworkSnakeState state) { ReplicateHeadPointer(state.Head); this.name = state.Name; this.snakeSkinID = int.Parse(state.Skin); if (state.Tail <= state.Head) { this.backboneLength = state.Tail + MAX_BACKBONE_POINTS - state.Head; } else { this.backboneLength = state.Tail - state.Head; } this.isTurbo = state.IsTurbo; NetworkSnakePartState snakePartState = new NetworkSnakePartState(); for (int i = 0; i < state.PartsLength; i++) { state.GetParts(snakePartState, i); if (snakePartState.Index == backboneStartIdx) { // We want to Lerp the head towards the new position interpolater.targetHeadPosition = new Vector2(snakePartState.Position.X, snakePartState.Position.Y); } else { this.backbone[snakePartState.Index] = new Vector2(snakePartState.Position.X, snakePartState.Position.Y); } } score = (int)state.Score; gameObject.SetActive(!state.IsDead); }
public void ReplicateSnakeState(NetworkSnakeState fSnakeState) { float headX = fSnakeState.GetParts(fSnakeState.Head).Position.X; float headY = fSnakeState.GetParts(fSnakeState.Head).Position.Y; // Debug.Log("Recieved head position = (" + headX + ", " + headY + ")"); //this.snakeState.head.transform.position = new Vector3(headX, headY, 0.0f); this.snakeState.snakeSkinID = 1;//int.Parse(snakeState.Skin); this.snakeState.name = fSnakeState.Name; this.snakeState.score = (int)fSnakeState.Score; }