- Home /
changing offset from gradual to increment
Hi everyone I have a script and I have figured out a couple of problems in it. But I still have one left in my game which is as you can see from the title I would like to change my offset animation from gradual to increment in the follow code
c# code:
using UnityEngine;
using System.Collections;
public class character : MonoBehaviour {
public float forwardSpeed = 20.0f;
public float rot = 0f;public float jumpSpeed = 100;public float gravity = 30f;
public Material newMaterialRefcs1;
public Material newMaterialRefcs2;
void Start () {
}
void Update () {
if( Input.GetKey(KeyCode.D)){
transform.position += -transform.right * forwardSpeed * Time.deltaTime;
renderer.material = newMaterialRefcs1;
float offset = Time.time * scrollSpeed;
renderer.material.SetTextureOffset("_MainTex", new Vector2(offset, 0));
}if( Input.GetKey(KeyCode.A)){
transform.position += transform.right * forwardSpeed * Time.deltaTime;
renderer.material = newMaterialRefcs2;
float offset = Time.time * scrollSpeed;
renderer.material.SetTextureOffset("_MainTex", new Vector2(offset, 0));
}
Vector3 isgrounded = transform.TransformDirection(Vector3.up);
if( Input.GetKeyDown(KeyCode.Space)&& Physics.Raycast(transform.position, isgrounded, 6)){
transform.position -= transform.up * jumpSpeed * Time.deltaTime*2;
}
Physics.gravity = new Vector3(0, gravity, 0);
transform.rotation = Quaternion.Euler(0, 0, transform.rotation.eulerAngles.z);
}
}
You likely are going to have to be clearer about what you are attempting and why to get an accurate answer. In order to jump a specific amount, change how you are calculating the new offset:
float offset += someAmount;
Note you might be better off with this code in FixedUpdate(). That way your frame updates/offsets will happen at a s$$anonymous$$dy rate.
I have figured it out with a lot of help from you
offset += someAmount;
I cant thank you enough I have been trying to figure this out for days
if you would like to post that as an answer I can mark it as correct