Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Can you fix the code for my movement for w to be a , s , d using System.Collections; using System.Collections.Generic; using UnityEngine; public class

Can you fix the code for my movement for w to be a, s, d
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class NewBehaviourScript : MonoBehaviour
{
const float speed =1.0f;
Vector3 velocity;
// Start is called before the first frame update
void Start()
{
velocity = speed * new Vector3(1.0f,0.0f,0.0f);
}
// Update is called once per frame
void Update()
{
Debug.Log("Hi");
if (Input.GetKey("w"))
{
velocity = new Vector3(velocity.x,1* velocity.y);
}
else if (Input.GetKey("a"))
{
velocity = new Vector3(-1* speed, velocity.y,0.0f);
}
else if (Input.GetKey("s"))
{
velocity = new Vector3(velocity.x,-1* speed, 0.0f);
}
else if (Input.GetKey("d"))
{
velocity = new Vector3(speed, velocity.y,0.0f);
}
transform.position +=(velocity * Time.deltaTime);
}
}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Beginning ASP.NET 4.5 Databases

Authors: Sandeep Chanda, Damien Foggon

3rd Edition

1430243805, 978-1430243809

More Books

Students also viewed these Databases questions

Question

Describe how to train managers to coach employees. page 422

Answered: 1 week ago