The code of Body color change when unity3d-controls the character's injury

Source: Internet
Author: User

The idea is to get the Skinnedmeshrenderer component first and then change the color of the component when it is initialized and then when the protagonist is injured.

1. Declaration Skinnedmeshrenderer

Private Skinnedmeshrenderer Smrenderer;

2. Initialize this Smrenderer

void Start () {

Smrenderer=transform. Find ("Player"). Getcomponent<renderer> () as Skinnedmeshrenderer;

}

3. Then let the object instantiate the color you need.

smrenderer.material.color=color.red;

4. You can also update the color of two materials in update

void Update () {

public float smooth=3; Transition smoothness This needs to be set at the beginning of the variable declaration

Smrenderer.material.color=color.lerp (Smrenderer.material.color,color.white,smooth*time.deltatime);

}

The code of Body color change when unity3d-controls the character's injury

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.