gpt-3.5-turbo-0613· OpenAI
WildChat-4.8M (AI2)
using System.Collections; using System.Collections.Generic; using UnityEngine; public…
- User
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class Player : MonoBehaviour { public float speed = 5f; // Speed of character movement
codeprivate Animator anim; private void Start() { anim = GetComponent<Animator>(); } void Update() { // Move character based on input axes float horizontalInput = Input.GetAxis("Horizontal"); float verticalInput = Input.GetAxis("Vertical"); // Calculate movement direction Vector2 movement = new Vector2(horizontalInput, verticalInput) * speed * Time.deltaTime; // Apply movement to the character’s position transform.Translate(movement); anim.SetFloat("moveX", movement.x); anim.SetFloat("moveY", movement.y); // Check if the player has the knife set as its child and is moving if (transform.Find("Knife") != null && horizontalInput != 0) { // Get the knife game object GameObject knife = transform.Find("Knife").gameObject; // Check if the player is moving right if (horizontalInput > 0) { // Set the knife’s transform position relative to the parent knife.transform.localPosition = new Vector3(0.41f, -0.02f, 0); // Set the knife’s sprite renderer flip component to false knife.GetComponent<SpriteRenderer>().flipX = false; } // Check if the player is moving left else if (horizontalInput < 0) { // Set the knife’s transform position relative to the parent knife.transform.localPosition = new Vector3(-0.41f, -0.02f, 0); // Set the knife’s sprite renderer flip component to true knife.GetComponent<SpriteRenderer>().flipX = true; } } } - Assistant
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class Player : MonoBehaviour { public float speed = 5f; // Speed of character movement
code